Drupal

Drupal 7: Decorate / wrap existing form as separate form with individual path

It's not an untypical situation: You'd like to use an existing Drupal CMS form as base for a custom form under a separate URL. In our example case we will decorate the Registration form "user_register_form" and create a separate registration form under a separate URL. This might be a custom alternative to modules like https://www.drupal.org/project/multiple_registration if they don't match your requirements.

How to track Google Ads conversions in Drupal (gtag.js) on specific pages

gtag.js Conversion Tracking in Drupal 7

My Drupal pro tip today only concerns Drupal 7 (sadly), because the tracking_code module is not available for Drupal 8 currently.

My little task was to add a Google Ads conversion tracking on a customer page. Google Ads uses gtag.js.

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

Drupal 8 on-demand error display with disabled cache via URL Parameter

Have you ever wanted to disable Drupal 8 cache and enable error reporting only for a specific page or to quickly debug a problem?
Here's a simple solution how to enable debugging and disable caching for a single call using a URL debug parameter

Drupal 7 / 8: Lightweight set / exchange domain specific front page (e.g. for landingpages)

Would you like to create a Landingpage for a specific topic in Drupal 7 / 8 on a separate landingpage domain (https://www.my-landingpage-example123.com/) as specific frontpage without using complex modules like Domain Access or multisite?
Then here's the lighweight way to go for you!

Drupal 8 Bug: The module standard does not exist. in Drupal\Core\Extension\ExtensionList->get()

We just ran into the Drupal 8 CMS Error message:

Drupal 8 Bug: The module standard does not exist. in Drupal\Core\Extension\ExtensionList->get()

Drupal 8 views set exposed filter (default) programatically with auto-submit

Setting a dynamic views exposed filter can be done via hook_form_FORM_ID_alter() regularly if it's just a prepopulation of the views exposed filter form.

But if you wish to immediately run the filters using better_exposed_filters auto-submit when the view is loaded you have to use hook hook_views_pre_build(). Otherwise setting the #default_value is just too late.

Use the following code:

Einordnung:

Drupal 8 Field Type Schema column add / change / delete HOOK_update

As heavily discucced in this years old issue: [#937442] there isn't a good solution or helper in Drupal core currently to change the schema of a custom field.

Modules like

  • field_collection
  • dynamic_entity_reference (#51)
  • address
  • viewsreference
  • ...

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. /**