code snippets

hook_geocoder_geocode_values_alter()

If you are using the geocoder module in Drupal 7 and you need the opportunity to alter the data being geocoded right before it gets sent to whichever geocoding service you are using, there is a hook for that. The hook is pretty much undocumented at this time, but it is there. hook_geocoder_geocode_values_alter() is available for you if you need it.

Moving Views Exposed Filters Form Elements Around

In Drupal 7, Views allows you to easily create exposed filters and alter a lot of the logic involved.  However, sometimes you get requests to add text to the form or position things in ways that the Views UI does not allow for.

I've got two solutions that are arguably not as Drupal-like as I would like, but I've run into some dead ends on occasion with trying to fullfill requests with only Drupal-like alterations.  And of course if there are better ways to do it, I am open to them.

Drupal View result count incorrect with Search API

In Drupal 7, if you use Views in combination with a search index from Search API, and you try to use the Global: Result summary in the header or footer of the View, you may find that the total number of results matches the number of items on the page, not the total number of items in the search index.

To correct this issue, hook_views_pre_execute will make everything work as you would expect.

Manage Drupal Feature Updates

When using Features module to move changes from one  development environment to the next, it can be tricky to track which Feature ought to be 'reverted' in order make the new code be incontrol.  Sure you can revert them all in one shot with `drush features-revert-all`, but that is pretty intensive to do especially on a production site and can lead to some race conditions.

Drupal: Altering Page Title and or Title Tag

Sometimes you need to alter the title that appears on the page and or the title tag in Drupal 7. If you need to make them both the same, a call to drupal_set_title() from within a hook_preprocess_page() will do it.

Render array - content with a wrapper

Here is an example of a basic rendering with content and a link

White screen in Drupal Development

In Drupal development it can be annoying to have just a blank white screen of death WSOD present you with no helpful information.

Adding these lines to your settings.php file will help make the WSOD more helpful
REMOVE them from production server.

Collapsible content in Drupal 7

Drupal 7 Makes it pretty easy to Have toggle-able / collapsible content by treating it as a fieldset.

php output debug

This output debug is is a quick snippet to use when Devel's krumo output is not available.

Pages

Subscribe to RSS - code snippets