Snippets

Drupal 8 Media: Format file size output / display

If you'd like to output Drupal 8 Media file size (mapper field) output in human-readable format, this snippet may help you!

in MYTHEME.theme file:

  1. function MYTHEME_preprocess_media(&$variables) {
  2.   /** @var \Drupal\media_entity\MediaInterface $media */
  3.   $media = $variables['elements']['#media'];
  4.  
  5.   if ($media->bundle() == 'document' && !empty($media-> field_document_size)) {

Shopware 5 PLZ-Bereich (Umkreis) versandkostenfrei für ausgewählte Kategorien


(IFNULL(us.zipcode,ub.zipcode) IS NOT NULL) AND (IFNULL(us.zipcode,ub.zipcode) IN ('32312', '32310', '12345'))
AND
MIN(SELECT 1 FROM s_articles_categories WHERE articleID=a.id AND categoryID IN (22,56)) AS erlaubtekategorie

Drupal 8: Override views row (views-view-fields.html.twig) in views style plugin

In the last days I developed the ZURB Foundation Views integration module for Drupal 8. To match the markup required by foundation accordion we first had to write a views style plugin in our module.

JTL-Shop4 Exportformat mit Varianteneigenschaften im Artikelnamen (z.B. für Idealo)

Nachfolgend das JTL Shop 4 Exportformat am Beispiel Idealo, wenn ihr Name und Wert der Varianten direkt hinter dem Artikelnamen ausgeben möchtet.

Dieser Trick wird z.B. verwendet, um Klicks auf (Kind-)Artikel zu vermeiden, die nur noch in bestimmten Größen lieferbar sind.


{strip}
{assign var="d" value="|"}
{$Artikel->kArtikel}{$d}
{$Artikel->cDeeplink}{$d}

Snippet: Drupal 8 Commerce: Show SKU in product variation inline entity form table

Before our modifications to the IEF table

Today I'd like to share a little snippet with you on how to add or remove fields from the inline entity form line items table in a product edit form.

By default that inline entity form table contains

  • Weight
  • Product variation title
  • Price
  • Status
  • Operations

What we'd like to do in our example is to

JTL Artikel pro Seite Limit 100 Maximum übersteuern (Suche / Kategorien)

Heute ein kleiner Tipp für Anwender von JTL-Shop 3 und JTL-Shop 4:

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 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') {