Browse Source

preprocess pour grid ressources

armansansd 3 years ago
parent
commit
77ed6b79fb

+ 40 - 0
web/sites/development.services.yml

@@ -4,6 +4,46 @@
 # 'example.settings.local.php' file, which sits next to this file.
 parameters:
   http.response.debug_cacheability_headers: true
+  twig.config:
+    # Twig debugging:
+    #
+    # When debugging is enabled:
+    # - The markup of each Twig template is surrounded by HTML comments that
+    #   contain theming information, such as template file name suggestions.
+    # - Note that this debugging markup will cause automated tests that directly
+    #   check rendered HTML to fail. When running automated tests, 'debug'
+    #   should be set to FALSE.
+    # - The dump() function can be used in Twig templates to output information
+    #   about template variables.
+    # - Twig templates are automatically recompiled whenever the source code
+    #   changes (see auto_reload below).
+    #
+    # For more information about debugging Twig templates, see
+    # https://www.drupal.org/node/1906392.
+    #
+    # Not recommended in production environments
+    # @default false
+    debug: true
+    # Twig auto-reload:
+    #
+    # Automatically recompile Twig templates whenever the source code changes.
+    # If you don't provide a value for auto_reload, it will be determined
+    # based on the value of debug.
+    #
+    # Not recommended in production environments
+    # @default null
+    auto_reload: null
+    # Twig cache:
+    #
+    # By default, Twig templates will be compiled and stored in the filesystem
+    # to increase performance. Disabling the Twig cache will recompile the
+    # templates from source each time they are used. In most cases the
+    # auto_reload setting above should be enabled rather than disabling the
+    # Twig cache.
+    #
+    # Not recommended in production environments
+    # @default true
+    cache: false
 services:
   cache.backend.null:
     class: Drupal\Core\Cache\NullBackendFactory

+ 24 - 17
web/themes/custom/popsu/popsu.theme

@@ -6,13 +6,6 @@
 
 use Drupal\Core\Template\Attribute;
 
-/* implements template_preprocess_views_view() */
-
-// function popsu_preprocess_views_view(&$vars) {
-//   $view = $vars['view'];
-//   kint($view);die();
-// }
-
 
 /* implements template_preprocess_views_view_unformatted() */
 
@@ -42,19 +35,33 @@ function popsu_preprocess_region(&$variables) {
 
 
 /**
- * Implements hook_preprocess_block().
+ * Implements hook_preprocess_page().
  */
 
-function popsu_preprocess_views_view_fields(&$variables){
-  
-  $entity = $variables['row']->_entity;
-  if($entity->hasField('field_programme')){
-      $target_id = $entity->get('field_programme')->getString();
-      //kint($variables['row']);die();
-      // $variables['row']['attributes'] = new Attribute();
-      // $variables['row']['attributes']->addClass("pouet-node-".$target_id);     
+// function popsu_preprocess_page(&$variables){
+//   $rows = $variables['rows'];
+// }
+
+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;
+
+    //notes
+    // $attrs['class'] = "popsu-node-".$prog_id;
+    // $rows[$id]["#options"]["col_class_custom"] = new Attribute($attrs);
+    //$rows[$id]["#options"]["col_class_custom"] = 'class';
+
   }
- 
 }
 
 function popsu_preprocess_views_view_field(&$variables){

+ 78 - 0
web/themes/custom/popsu/templates/views/views-view-grid.html.twig

@@ -0,0 +1,78 @@
+{#
+/**
+ * @file
+ * Default theme implementation for views to display rows in a grid.
+ *
+ * Available variables:
+ * - attributes: HTML attributes for the wrapping element.
+ * - title: The title of this group of rows.
+ * - view: The view object.
+ * - rows: The rendered view results.
+ * - options: The view plugin style options.
+ *   - row_class_default: A flag indicating whether default classes should be
+ *     used on rows.
+ *   - col_class_default: A flag indicating whether default classes should be
+ *     used on columns.
+ * - items: A list of grid items. Each item contains a list of rows or columns.
+ *   The order in what comes first (row or column) depends on which alignment
+ *   type is chosen (horizontal or vertical).
+ *   - attributes: HTML attributes for each row or column.
+ *   - content: A list of columns or rows. Each row or column contains:
+ *     - attributes: HTML attributes for each row or column.
+ *     - content: The row or column contents.
+ *
+ * @see template_preprocess_views_view_grid()
+ *
+ * @ingroup themeable
+ */
+#}
+{%
+  set classes = [
+    'views-view-grid',
+    options.alignment,
+    'cols-' ~ options.columns,
+    'clearfix',
+  ]
+%}
+{% if options.row_class_default %}
+  {%
+    set row_classes = [
+      'views-row',
+      options.alignment == 'horizontal' ? 'clearfix',
+    ]
+  %}
+{% endif %}
+{% if options.col_class_default %}
+  {%
+    set col_classes = [
+      'views-col',
+      options.alignment == 'vertical' ? 'clearfix',
+    ]
+  %}
+{% endif %}
+{% if title %}
+  <h3>{{ title }}</h3>
+{% endif %}
+<div{{ attributes.addClass(classes) }}>
+  {% if options.alignment == 'horizontal' %}
+    {% for row in items %}
+      <div{{ row.attributes.addClass(row_classes, options.row_class_default ? 'row-' ~ loop.index) }}>
+        {% for column in row.content %}
+          <div{{ column.attributes.addClass(col_classes, options.col_class_custom ,options.col_class_default ? 'col-' ~ loop.index) }}>
+            {{- column.content -}}
+          </div>
+        {% endfor %}
+      </div>
+    {% endfor %}
+  {% else %}
+    {% for column in items %}
+      <div{{ column.attributes.addClass(col_classes, options.col_class_default ? 'col-' ~ loop.index) }}>
+        {% for row in column.content %}
+          <div{{ row.attributes.addClass(row_classes, options.row_class_default ? 'row-' ~ loop.index) }}>
+            {{- row.content -}}
+          </div>
+        {% endfor %}
+      </div>
+    {% endfor %}
+  {% endif %}
+</div>