Drupal 7

Snippet: Drupal 7 render view in code and hide if empty results

Use this simple snippet to embed a view in code and only display it if the view has at least one result (prevent rendering empty views markup):

  1. $view = views_get_view('your_view_name');
  2. $view->set_display('your_view_display');
  3. // Only display the view if it has results and the user has access.
  4. if ($view->access('your_view_display')) {        
  5.         // Example argument

Drupal 7 entityreference autocomplete: Improve the ENTER keydown behaviour (select first on enter)

I created this issue and snippet as better entityreference.module autocomplete widget usability solution in: ‎

Define extra fields (display) in code for Drupal Commerce products with auto AJAX handling and product+product node types handling

Today I had the challenge to add some extra (programatically calculated) fields to show in commerce.module product display nodes. In our specific case it was a "base price" that should be shown additionally to calculated SALE prices.

Drupal 7 Snippet: Add first level menu item mlid as body class for sectionizing your pages

If you'd like to separate your website areas by main menu first levels (for example colourize all areas in a different colour) a body class outputting the first level mlid may help you (otherwise you can for example use context.module or things like that!):

Here's the snippet you may use:

  1. function YOUR_THEME_preprocess_html(&$variables, $hook) {

Drupal 7 E-Mail Ausgabe debuggen / protokollieren mit DevelMailLog

Heute möchte ich Euch in einem kurzen HowTo zeigen, wie ihr E-Mails aus Drupal ganz einfach mithilfe des Moduls devel.module und mailsystem.module (oder einer settings.php Konfigurationseinstellung) abfangen und den Quellcode debuggen könnt.

Linktipp: Great blog post about Drupals entity_metadata_wrapper

Just WHAO! You should read it :)
I've been using them for a long period of time already but there were some still things to learn!

Snippet: Drupal Commerce: Hide subtotal (DE: "Zwischensumme") in commerce_price_formatted_components

  1. /**
  2.  * Implements HOOK_preprocess_commerce_price_formatted_components
  3.  */
  4. function YOUR_MODULE_preprocess_commerce_price_formatted_components(&$variables) {
  5.   // Do not show the subtotal (Zwischensumme) in components table
  6.   if (!empty($variables['components']['base_price'])) {
  7.     unset($variables['components']['base_price']);
  8.   }
  9. }

Drupal Commerce: Determine currently selected product variation (or default delta)

Today I'd like to provide you with a little commerce.module snippet to determine the currently selected product variation (using commerce_product_reference.module) of a product display with several variations.

I had to search hard for it so here's the code for you:

  1. // Determine the currently selected product or default product for this product display

Drupal: WYSIWYG + CKEditor + Live-Rechtschreibprüfung via scayt aktivieren und Sprache auf Deutsch einstellen

Heute ein kleines Drupal Modul-Snippet zur Aktivierung der autom. Rechtschreibprüfung via Scayt im CKEditor unter Einsatz des wysiwyg.module inkl. Sprachumschaltung auf Deutsch für die Rechtschreibprüfung (Standard-Sprache)

Never panelize a commerce product display

Hinweis: Dieser Blog-Eintrag stellt einen Hinweis an mich selbst dar, könnte aber dem ein oder anderen Drupal Entwickler bei der Verwendung von commerce.module und panelizer.module ein wertvoller Tipp sein!