Snippet

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

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

MySQL: Tabelleninhalte nach UTF-8 umwandeln (von latin1 o.Ä.)

Mit folgendem MySQL Befehl könnt ihr relativ simpel ehemalige latin1 Felder zu UTF-8 umwandeln, z.B. nachdem ihr die Collation der gesamten Tabelle umgewandelt habt:


UPDATE tablename SET spaltenname=CONVERT(BINARY CONVERT(spaltenname USING latin1)USING utf8);