Messages api, make message programmatically for orders

I wanted to add a message to orders when I did some auto approving of orders. To add some trace of that you need to load user which will be the one that did that. Send $values that will be used for token replacement in message and also select which message type you are going to use. In here I made a clone of default message "commerce_order_admin_comment" and used that.

Life of a view and what and where to hook or alter

Often I have a need to alter a bit output of a view, either the markup or just query, it's important to know where to hook in a life of a view, here is the list of hooks and alters.
 

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);

 

 

Find and change module weight with drush

Run this in terminal

drush php-eval "drush_print_r(db_select('system', 's') ->fields('s', array('weight')) ->condition('name', 'some_module', '=') ->execute() ->fetchField())";

and then when you get the required modules weight, change it with