Drupal Dump

Drupal Snippets, Hacks and more....

495 posts since 2011

How to style elements that change ids when ajax actions replace them

In drupal, when you have ajax refreshing some content, elements get new ids when they refresh. So some input element that was "edit-get-score"  becomes "edit-get-score-2" then ""edit-get-score-3" etc.
So to match them properly by ID you can use this. Which is CSS attribute selector using sort of a wildcard

Get list of all the hooks your site currently uses

In includes/module.inc, find the module_implements() function (around line 715 in Drupal 7). At the top of the function, just add this below and you will get huge output of all the hooks that are called.

 

function module_implements($hook, $sort = FALSE, $reset = FALSE) {
  drupal_set_message("hook_$hook");
  ......

 

Find out which theme function to call to alter each element on page

This is a hack on how to get output of which theme function to call to alter each element on page. So you will need to go to In includes/theme.inc in the Drupal 7 theme() function, around line 1161 and change $output from one line to two lines and to have this code below. You will get theme suggestions all around the page, which will be messy but will help you find what you need.

Add a field to entity programmatically

Wanting to add field to some entity (we here pick order entity) by code, for example when deploying to production, use this snippet of code and you will have this new field added.

Clear cache of particular entity

For debugging purposes I need to clear cache for particular drupal commerce order, but this can be done for any entity, just replace table name and id's in code below

 $table = 'cache_entity_commerce_order';
 $id ="776764";
 cache_clear_all($id, $table);

 

 

Delete stale CSS and JS files faster

To delete stale CSS and JS files from server, you need to add

variable_set('drupal_stale_file_threshold', 86400);

to your settings.php and change the value from default 30 days (2592000) to for example 1 day above.
They will be deleted on cron run.