activated twig_xdebug, added proper classes to views_view_gird columns
This commit is contained in:
@@ -43,24 +43,35 @@ function popsu_preprocess_region(&$variables) {
|
||||
// }
|
||||
|
||||
function popsu_preprocess_views_view_grid(&$variables){
|
||||
$rows = $variables['rows'];
|
||||
// we pass all variables by reference
|
||||
// https://www.php.net/manual/en/language.references.php
|
||||
$items =& $variables['items'];
|
||||
|
||||
foreach ($rows as $id => $row) {
|
||||
// loop through grid items (row and cols) not through views\rows
|
||||
foreach ($items as $r => &$row) {
|
||||
foreach ($row['content'] as $c => &$col) {
|
||||
|
||||
$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;
|
||||
// get the entity
|
||||
$entity = $col['content']["#row"]->_entity;
|
||||
|
||||
//notes
|
||||
// $attrs['class'] = "popsu-node-".$prog_id;
|
||||
// $rows[$id]["#options"]["col_class_custom"] = new Attribute($attrs);
|
||||
//$rows[$id]["#options"]["col_class_custom"] = 'class';
|
||||
// build generique classe
|
||||
$classes = array(
|
||||
$entity->getEntityTypeId(),
|
||||
$entity->getEntityTypeId().'-'.$entity->bundle(),
|
||||
$entity->getEntityTypeId().'-'.$entity->bundle().'-'.$entity->id(),
|
||||
);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user