Переглянути джерело

activated twig_xdebug, added proper classes to views_view_gird columns

bach 3 роки тому
батько
коміт
b8a8ccff9a
4 змінених файлів з 144 додано та 18 видалено
  1. 3 0
      composer.json
  2. 113 2
      composer.lock
  3. 1 0
      config/sync/core.extension.yml
  4. 27 16
      web/themes/custom/popsu/popsu.theme

+ 3 - 0
composer.json

@@ -126,5 +126,8 @@
             "Add Views EntityReference filter to be available for all entity reference fields https://www.drupal.org/project/drupal/issues/2429699" : "https://www.drupal.org/files/issues/2021-03-06/2429699-389.patch"
           }
         }
+    },
+    "require-dev": {
+        "drupal/twig_xdebug": "^1.2"
     }
 }

+ 113 - 2
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "031fcb88faba70428c9f0ec049e89d3e",
+    "content-hash": "e068c60c82edbbf3ad0fbb55665b3703",
     "packages": [
         {
             "name": "alchemy/zippy",
@@ -15292,7 +15292,118 @@
             "time": "2020-12-21T09:30:01+00:00"
         }
     ],
-    "packages-dev": [],
+    "packages-dev": [
+        {
+            "name": "ajgl/breakpoint-twig-extension",
+            "version": "0.3.5",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/ajgarlag/AjglBreakpointTwigExtension.git",
+                "reference": "9875feea0ac4bc3c9f308c62bae4727669d6052a"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/ajgarlag/AjglBreakpointTwigExtension/zipball/9875feea0ac4bc3c9f308c62bae4727669d6052a",
+                "reference": "9875feea0ac4bc3c9f308c62bae4727669d6052a",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.6",
+                "twig/twig": "^1.34|^2.0|^3.0"
+            },
+            "require-dev": {
+                "friendsofphp/php-cs-fixer": "^2.18",
+                "symfony/framework-bundle": "^2.7|^3.4|^4.4|^5.2",
+                "symfony/phpunit-bridge": "^4.4|^5.2",
+                "symfony/twig-bundle": "^2.7|^3.4|^4.4|^5.2"
+            },
+            "suggest": {
+                "ext-xdebug": "The Xdebug extension is required for the breakpoint to work",
+                "symfony/framework-bundle": "The framework bundle to integrate the extension into Symfony",
+                "symfony/twig-bundle": "The twig bundle to integrate the extension into Symfony"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "0.3.x-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Ajgl\\Twig\\Extension\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Antonio J. García Lagar",
+                    "email": "aj@garcialagar.es",
+                    "homepage": "http://aj.garcialagar.es",
+                    "role": "developer"
+                }
+            ],
+            "description": "Twig extension to set breakpoints",
+            "homepage": "https://github.com/ajgarlag/AjglBreakpointTwigExtension",
+            "keywords": [
+                "Xdebug",
+                "breakpoint",
+                "twig"
+            ],
+            "support": {
+                "issues": "https://github.com/ajgarlag/AjglBreakpointTwigExtension/issues",
+                "source": "https://github.com/ajgarlag/AjglBreakpointTwigExtension/tree/0.3.5"
+            },
+            "time": "2021-02-08T10:48:05+00:00"
+        },
+        {
+            "name": "drupal/twig_xdebug",
+            "version": "1.2.0",
+            "source": {
+                "type": "git",
+                "url": "https://git.drupalcode.org/project/twig_xdebug.git",
+                "reference": "8.x-1.2"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://ftp.drupal.org/files/projects/twig_xdebug-8.x-1.2.zip",
+                "reference": "8.x-1.2",
+                "shasum": "fa4dfc8edebc0628257b998ca6521790c52250e8"
+            },
+            "require": {
+                "ajgl/breakpoint-twig-extension": "^0.3.4",
+                "drupal/core": "^8 || ^9"
+            },
+            "type": "drupal-module",
+            "extra": {
+                "drupal": {
+                    "version": "8.x-1.2",
+                    "datestamp": "1588041097",
+                    "security-coverage": {
+                        "status": "covered",
+                        "message": "Covered by Drupal's security advisory policy"
+                    }
+                }
+            },
+            "notification-url": "https://packages.drupal.org/8/downloads",
+            "license": [
+                "GPL-2.0-or-later"
+            ],
+            "authors": [
+                {
+                    "name": "charginghawk",
+                    "homepage": "https://www.drupal.org/user/2626341"
+                }
+            ],
+            "description": "Enables Xdebug breakpoints in Twig.",
+            "homepage": "https://www.drupal.org/project/twig_xdebug",
+            "support": {
+                "source": "https://git.drupalcode.org/project/twig_xdebug"
+            }
+        }
+    ],
     "aliases": [],
     "minimum-stability": "stable",
     "stability-flags": {

+ 1 - 0
config/sync/core.extension.yml

@@ -128,6 +128,7 @@ module:
   token: 0
   toolbar: 0
   translation_views: 0
+  twig_xdebug: 0
   update: 0
   url_to_video_filter: 0
   user: 0

+ 27 - 16
web/themes/custom/popsu/popsu.theme

@@ -43,24 +43,35 @@ function popsu_preprocess_region(&$variables) {
 // }
 
 function popsu_preprocess_views_view_grid(&$variables){
-  $rows = $variables['rows'];
-
-  foreach ($rows as $id => $row) {
-
-    $entity = $row["#row"]->_entity;
-    $prog_id = $entity->get('field_programme')->getString();
-    
-    // une fois qu'on obtient l'id du programme 
-    // on crée une class pour chaque colonne
-    $options = $row["#view"]->style_plugin->options;
-    //V0
-    $options['col_class_custom'] = "popsu-node-".$prog_id;
+  // we pass all variables by reference
+  // https://www.php.net/manual/en/language.references.php
+  $items =& $variables['items'];
+
+  // loop through grid items (row and cols) not through views\rows
+  foreach ($items as $r => &$row) {
+    foreach ($row['content'] as $c => &$col) {
+
+      // get the entity
+      $entity = $col['content']["#row"]->_entity;
+
+      // build generique classe
+      $classes = array(
+        $entity->getEntityTypeId(),
+        $entity->getEntityTypeId().'-'.$entity->bundle(),
+        $entity->getEntityTypeId().'-'.$entity->bundle().'-'.$entity->id(),
+      );
 
-    //notes
-    // $attrs['class'] = "popsu-node-".$prog_id;
-    // $rows[$id]["#options"]["col_class_custom"] = new Attribute($attrs);
-    //$rows[$id]["#options"]["col_class_custom"] = 'class';
+      // if field_programme exists, add a class
+      if ($entity->hasField('field_programme')) {
+        $prog_id = $entity->get('field_programme')->getString();
+        $classes[] = "programme-".$prog_id;
+      }
 
+      // add the classes to the column
+      // Drupal\Core\Template\Attribute 
+      // https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Template%21Attribute.php/class/Attribute/8.2.x
+      $col['attributes']->addClass($classes);
+    }
   }
 }