Outside Links collection sticky icon

Sometimes you find just the right resources that fulfill certain need and nothing much should be added to them, in those cases I will just collect them on this page and add short comment why is this so.

How to combine Git and Drush to have perfect workflow for site maintenance, information and examples are here
http://www.jenlampton.com/blog/keeping-your-drupal-site-date-git-and-drush

Setting upt perfect Git + Drush workflow, read here
http://www.acquia.com/blog/using-git-drush-win-workflow

List all available entites on your site when you need exact machine names

dpm(entity_get_info());

and you will get all the info you will need, like proper machine names.

Altering views exposed filters with hook_views_query_alter()

To alter the form output we need to use form alter and overide array. We are going to add few options to filters that group filter options together, in this case we are dealing with list of countries.

/**

* Implements hook_form_alter();
*
* @param $form
* @param $form_state
* @param $form_id
*/
function my_module_form_views_exposed_form_alter(&$form, &$form_state) {
if($form['#id'] == 'views-exposed-form-warranty-admin-page-3' || $form['#id'] == 'views-exposed-form-warranty-admin-page-1') {

$additional_options = array();

Disabling Generate automatic URL alias checkbox on node edit/add by default

Disabling Generate automatic URL alias is not possible with configuration, this needs to be done with code.

In hook_form_alter we call

/**
* Implements hook_form_alter().
*/
function myModule_form_alter(&$form, &$form_state, $form_id) {
// disable auto generating of URLs with pathauto
if ($form['#entity_type'] == "node"){
$form['#after_build'][] = 'myModule_after_build';
}

and then we create that after build myModule_after_build

/**
* Custom after build function
*/
function myModule_after_build($form, &$form_state) {

List all machine name values for permissions in drupal 7

// Render permission overview:
$options = array();
foreach (module_list(FALSE, FALSE, TRUE) as $module) {
if ($permissions = module_invoke($module, 'permission')) {
// List only the modules that have permissions.
dsm($module);
dsm($permissions);
}
}

you can also use Devel module and Enable "Display machine names of permissions and modules" option and will have it on hover at permission page.

Drupal commerce - change order status when order is locked

This is a helper function when order is locked, validation fails and status cant be changes.

$order = commerce_order_load('219215');
commerce_order_status_update($order, 'pending', FALSE, FALSE);
commerce_order_save($order);

Drupal commerce - change order status when order is locked

This is a helper function when order is locked, validation fails and status cant be changes.

$order = commerce_order_load('219215');
commerce_order_status_update($order, 'pending', FALSE, FALSE);
commerce_order_save($order);

Show variables in devel way(krumo) with watchdog

watchdog('debug',kprint_r($var, TRUE, NULL));

Integrating 3rd party libraries to drupal 7, libraries with namespaces

I am trying to integrate pay with amazon to drupal site and had a hello of a time, trying to figure out how to do that. They use namespaces and that is not something so common in drupal 7. So to understand it better, check out this video and this blog post

How to use namespaces and what are they
http://buildamodule.com/video/drupal-8-developer-prep-namespacing-and-au...

How to properly setup namespaces in drupal 7 and combine it with drupal 7 code
http://pixel5.us/node/35

hook_form_alter is not called if form fails validation

There is interesting discusion about this here
https://www.drupal.org/node/671574#comment-6466782

and basically how form is cached once something is entered in it, so if validation fails, form will ignore hook_form_alters in that case and loose changes you made. There is a good comment about that here https://www.drupal.org/node/671574#comment-9441525

"It's even incorrect to state that forms are only built once by design, because they aren't. They're only built once if caching is enabled.
..."

Solutions are to use #attached, #after_build and perhaps #pre_render.