Snippet

JTL-Shop 4: AJAX events / hooks / bindings "contentLoaded"

Ein typisches Problem im Umgang mit AJAX ist die (re-)Initialisierung von Scripts auf den nachträglich geladenen Inhalt. Im JTL-Shop 4 stößt man darauf beispielsweise auf Kategorieübersichten bei der Seitennavigation.

Viele Systeme, viele Lösungen

Drupal 7 Snippet: Photoswipe: Only output first image of image field, but show the rest in swipe gallery

Simple snippet to only output the first image of an imagefield in a view and show the rest of the gallery in the photoswipe overlay.

Hint: Don't forget to add the photoswipe-gallery class on the field wrapper in views settings: http://cgit.drupalcode.org/photoswipe/tree/README.txt?h=7.x-2.x

  1. /**
  2.  * Implements hook_views_pre_render().
  3.  */

Drupal 7 Snippet: Add lightbox fallback for image_link_formatter

Little Drupal 7 snippet for the image_link_formatter module (https://www.drupal.org/project/image_link_formatter) to add a fallback to lightbox in size large if no link is given.
Should work the same with other fallbacks (colorbox, etc.).

With some time you could create a clean field formatter from this containing the hard coded values as field display settings.

  1. /**

Drupal 8: Looping through EntityReferenceItem(s) / EntityReferenceRevisionsItem(s) to get Target Entities is wrong

I just had the case to iterate over EntityReferenceRevisionsItem's which are similar to EntityReferenceItem to get the target entities,

My code snippet was (WRONG EXAMPLE):

  1. $subParagraphsER = $paragraph->get('field_paragraphs_paragraphs');
  2. foreach ($subParagraphsER as $subParagraph) {
  3. ...
  4. }

Drupal hide fieldgroup in HOOK_form_alter

JTL-Shop4: SSL / https via Datenbank deaktivieren (Migration)

Heute ein kleiner Tipp für JTL-Shop4 Administratoren: Falls ihr im Rahmen einer Migration die Einstellung für SSL direkt in der Datenbank (+ ggf. .htaccess bedenkden!) deaktivieren müsst, geht das mit folgendem Befehl:


UPDATE `teinstellungen` SET cWert = 'N' WHERE `cName` LIKE 'kaufabwicklung_ssl_nutzen'

Der Wert für "Permanent" ist hier z.B. "P".

Drupal 7: Ensure HOOK_node_view is not called by search indexing

When using HOOK_node_view() you should take care because when the search (Search API especially) is indexing, this hook is also being called. You can not rely on a user displaying the node display currently. Here's a way to ensure this...

  1. function MYMODULE_node_view($node, $view_mode, $langcode) {
  2.   if ($view_mode != 'full' || arg(0) != 'node') {

Drupal 7 Commerce: Compare customer profile addresses / check address equality (shipping / billing)

I had the requirement to check the equality of addresses in customer orders (billing / shipping) and wrote two helper functions for that.

Perhaps you'll run into the same demand one day. Then please leave a comment here and in the original issue I posted on Drupal.org to document your demand for such a solution: See https://www.drupal.org/node/2680997

Thank you!

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: ‎