-
Updating a MySQL Field Based on its Row’s Position in a Select
Let’s say you have the following data in a table:
name position Stevie Ray Vaughan 1 Derek Trucks 3 Joe Bonamassa 2 Now, what if we wanted to update the position value of each row to match the order if we were to sort by name…
-
Overriding Image Field Attribute Forms
Another quick example for you…
Here’s what the default image field form looks like, if you have enabled alt and title attributes:
One way to modify the titles and help text (descriptions) of the Alternate text and Title attributes here is to use hook_field_widget_form_alter. Here’s what your code might look like:
1234567891011121314151617181920212223/*** Implements hook_field_widget_form_alter().*/function mymodule_field_widget_form_alter(&$element, &$form_state, $context) {// see http://drupal.stackexchange.com/a/54911 for a more "universal approach"if (isset($element['#field_name']) && $element['#field_name'] == 'field_portfolio_images') {foreach (element_children($element) as $delta) {$element[$delta]['#process'][] = 'mymodule_field_widget_process_field_portfolio_image';}}}/*** Process callback for the field_portfolio_image title attribute form changes*/function mymodule_field_widget_process_field_portfolio_image($element, &$form_state, $form) {if ($element['title']['#access']) {$element['title']['#title'] = t('My New title');$element['title']['#description'] = t('Here are my custom instructions.');}return $element;}Here’s the result:
-
Applescript to Interact with iTerm2
iTerm2 has decent support for Applescript. You can work with sessions, profiles, tabs, and more through Applescript. I only have one example, but it’s something I use in the real-world, so maybe it’ll help someone else.
The following script will open a new tab for every server in the list, and execute a command on that server. Let’s say a new version of Drush is available. I’d use this script to log into every server (we have no less than 15 servers) and check which version of Drush the server is running. I could then quickly update if needed, and I’m already logged in to do so.
-
Sorting by Specific Fields with Apache Solr
Recently I had to configure an Apache Solr search page to have the results sorted by a date field. We’re using the apachesolr module, which has a number of useful hooks, two of which we’ll use to accomplish this custom sort.
If you browse to Administration » Reports » Apache Solr search index you will see a list of the indexed fields (example shown below). Most of the documentation I’ve seen out there regarding apachesolr sorting says you can use $query->setAvailableSort() and $query->setSolrSort() within an implementation of hook_apachesolr_query_prepare() , but there is at least one caveat: the field you want to sort on must be a single-value field! Here’s a look at the field list on the site I’m working on:
-
Userscript: Hulu Right-Click for Pop Out Video
Hulu’s default rather large video player is usually too big for my needs. I prefer the “Pop Out” player. So, I often load the large video, click the cog wheel, move my mouse to the “popout” link, click it, then close the main window. It’s been a pain in the butt. So, I took some time to write a simple userscript that lets you right-click on any video thumbnail to open its video in the popout immediately. It’s working great for me but I have not tested it elsewhere, so I won’t be surprised if it doesn’t work for you… just let me know in the comments below…
http://userscripts.org/scripts/show/311800UPDATE: I rewrote this as a Chrome Extension and published it. View the blog post.