class type-media sur body et position block third
This commit is contained in:
@@ -11,23 +11,29 @@ use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Transliteration\TransliterationInterface;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\Core\Template\Attribute;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
|
||||
function eql_preprocess_html(&$variables) {
|
||||
$node = \Drupal::routeMatch()->getParameter('node');
|
||||
if ($node){
|
||||
$variables['attributes']['class'][] = 'node-type-' . $node->bundle();
|
||||
$variables['attributes']['class'][] = 'node-id-' . $node->id();
|
||||
}
|
||||
if ($node instanceof NodeInterface) {
|
||||
|
||||
if ($node instanceof \Drupal\node\NodeInterface) {
|
||||
$variables['attributes']['class'][] = 'node-type-' . $node->bundle();
|
||||
$variables['attributes']['class'][] = 'node-id-' . $node->id();
|
||||
|
||||
// Pour les ressources : ajoute la classe de type de ressource
|
||||
if ($node->bundle() === 'ressource' && $node->hasField('field_type_de_ressource')) {
|
||||
foreach ($node->get('field_type_de_ressource')->referencedEntities() as $term) {
|
||||
$label = $term->label();
|
||||
$css_class = 'type-' . Html::getClass($label);
|
||||
$variables['attributes']['class'][] = $css_class;
|
||||
// Liste des champs à traiter pour générer des classes dynamiques
|
||||
$fields_to_classify = [
|
||||
'field_type_de_ressource' => 'type-',
|
||||
'field_type_de_media' => 'type-media-',
|
||||
];
|
||||
|
||||
foreach ($fields_to_classify as $field_name => $prefix) {
|
||||
if ($node->hasField($field_name) && !$node->get($field_name)->isEmpty()) {
|
||||
foreach ($node->get($field_name)->referencedEntities() as $term) {
|
||||
$label = $term->label();
|
||||
$css_class = $prefix . Html::cleanCssIdentifier(strtolower($label));
|
||||
$variables['attributes']['class'][] = $css_class;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user