Drupal 7 Developer Snippet: Embed a minipanel in Code in Drupal 7 using contexts

Not much more to say... :)

  1. ctools_include('context');
  2. $panel_mini = panels_mini_load('my_minipanel_machinename');
  4. // In this example the mini panel has two contexts: A displayed user argument (required) and the current logged in user.
  5.   $displayed_user_context = ctools_context_create('entity:user', $displayed_user);
  6.   $user_context = ctools_context_create('entity:user', $user);

Drupal subscriptions.module: Exclude (current) user from notifications about own changes via HOOK

With the following little HOOK snippet you can exclude users from receiving notifications about own changes in the subscriptions.module:

  1. /**
  2.  * Implements HOOK_subscriptions_queue_alter.
  3.  */
  4. function MYMODULE_subscriptions_queue_alter(&$event){
  5.   global $user;
  6.   if(!empty($user)){
  7.     // Prevent users from receiving notifications about own changes.

Drupal 7 set JavaScript / jQuery trigger on autocomplete field option

With this little snippet you can easily set a trigger on autocomplete field options (suggestions) click:

  1. $(document).on('click', 'div.reference-autocomplete', function(e) {
  2.   // Do what you need to do ;)
  3. });

It's not that easy because the selection click does not trigger any change event on the parent input.

Solution to: Call to undefined function node_form_validate on ajax form submit

If you're running into the JavaScript alert error message on creating an AJAXified node form:

Call to undefined function node_form_validate() ...

... the reason might be that the $form_states array contains wrong information which files to load on form build.

Drupal 7 API: Trigger views AJAX refresh via JavaScript or from PHP using ajax_command_invoke

Drupal 7 views.module allows to refresh ajaxified views
dynamically via a javascript call.

Implementation in JavaScript

The JavaScript call is simple:

  1.   jQuery('.view-id-XXX').trigger('RefreshView');

Implementation in PHP

Drupal Multisite Cron

Bei einer Multisite-Installation via Drupal besteht das Problem, dass der Cron nur für die default-Seite ausgeführt wird.

Eine Möglichkeit dies zu lösen ist die Nutzung des Moduls "poormanscron". Hier werden den Benutzern allerdings manchmal Fehlermeldungen / Notizen der ausgeführten Module angezeigt.

Code Snippet: Browser Caching in Live-Applications verhindern via Meta-Angaben

Mit dem nachfolgenden Code-Snippet verhindert ihr via Meta-Tags das Caching von Seiten z.B. in Live-Anwendungen, die sich regelmäßig aktivieren.

<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="expires" content="0"/>

Drupal Commerce: Add "Update cart" button on top of cart view

Today I'd like to provide a short snippet (hook) to add an additional "Update cart" button on top of the cart view in commerce.module.

  1. /**
  2.  * Implements hook_form_FORM-ID_alter.
  3.  * @param type $form
  4.  * @param type $form_state
  5.  */
  6. function MY-MODULE_form_views_form_commerce_cart_form_default_alter(&$form, &$form_state) {

Drupal 7 Commerce HOWTO: Get commerce_add_to_cart_confirmation Message out of the Messages

The commerce_add_to_cart_confirmation.module uses the drupal_set_message() mechanism to display the add to cart layer after a product has been added to the cart.

This is being triggered via a rules.module rule, provided by the module.

Drupal Commerce: "Order total", "Billing information" & "Shipping information" übersetzen

Heute ein kurzer aber wichtiger Tipp, wenn ihr Drupal Commerce (auch Commerce Kickstart) verwendet und sich die Texte "Order total", "Billing information" & "Shipping information" im Bestellablauf nicht übersetzen lassen.