ressource type-en-images, php js et css
This commit is contained in:
@@ -14,9 +14,18 @@ use Drupal\Core\Template\Attribute;
|
||||
|
||||
function eql_preprocess_html(&$variables) {
|
||||
$node = \Drupal::routeMatch()->getParameter('node');
|
||||
if ($node){
|
||||
if ($node instanceof 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,16 +42,7 @@ function eql_preprocess_node(&$variables){
|
||||
$type_protagoniste = $node->get('field_type_de_protagoniste')->getString();
|
||||
$variables['attributes']['class'][] = 'type-de-protagoniste-' . $type_protagoniste;
|
||||
}
|
||||
|
||||
// if ($node->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
|
||||
// // Récupère la valeur de field_type_de_ressource
|
||||
// $type_de_ressource_entity = $node->get('field_type_de_ressource')->entity;
|
||||
// if ($type_de_ressource_entity) {
|
||||
// $type_de_ressource_name = $type_de_ressource_entity->getName();
|
||||
// // Ajoute la classe CSS basée sur la valeur du type de ressource
|
||||
// $variables['attributes']['class'][] = 'type-de-ressource-' . Html::cleanCssIdentifier($type_de_ressource_name);
|
||||
// }
|
||||
// }
|
||||
|
||||
if ($node->getType() === 'ressource' && $node->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
|
||||
foreach ($node->get('field_type_de_ressource')->referencedEntities() as $term) {
|
||||
$label = $term->label(); // ex: "Presse"
|
||||
@@ -51,6 +51,26 @@ function eql_preprocess_node(&$variables){
|
||||
}
|
||||
}
|
||||
}
|
||||
function eql_preprocess_page(array &$variables) {
|
||||
$node = \Drupal::routeMatch()->getParameter('node');
|
||||
if ($node instanceof \Drupal\node\NodeInterface && $node->bundle() === 'ressource') {
|
||||
if ($node->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
|
||||
foreach ($node->get('field_type_de_ressource')->referencedEntities() as $term) {
|
||||
$label = $term->label();
|
||||
$css_class = 'type-' . \Drupal\Component\Utility\Html::getClass($label);
|
||||
|
||||
// S'assurer que les attributs existent
|
||||
if (!isset($variables['page']['top']['#attributes'])) {
|
||||
$variables['page']['top']['#attributes'] = ['class' => []];
|
||||
}
|
||||
|
||||
$variables['page']['top']['#attributes']['class'][] = $css_class;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function eql_preprocess_field(&$variables) {
|
||||
$node = \Drupal::routeMatch()->getParameter('node');
|
||||
@@ -76,6 +96,7 @@ function eql_preprocess_field(&$variables) {
|
||||
|
||||
function eql_preprocess_layout__threecol_25_50_25(&$variables) {
|
||||
$node = \Drupal::routeMatch()->getParameter('node');
|
||||
|
||||
if($node->gettype() == "projet"){
|
||||
$variables['content']['top_bottom'] = []; /////// déclare les nvx array
|
||||
$variables['content']['top_right'] = [];
|
||||
@@ -102,39 +123,27 @@ function eql_preprocess_layout__threecol_25_50_25(&$variables) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($node && $node->getType() === 'ressource') {
|
||||
if ($node->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
|
||||
$terms = $node->get('field_type_de_ressource')->referencedEntities();
|
||||
if (!empty($terms)) {
|
||||
$label = $terms[0]->label();
|
||||
$css_class = 'type-' . Html::cleanCssIdentifier(strtolower($label));
|
||||
|
||||
// Appliquer cette classe à la région "top"
|
||||
if (!isset($variables['region_attributes']['top'])) {
|
||||
$variables['region_attributes']['top'] = new \Drupal\Core\Template\Attribute();
|
||||
}
|
||||
|
||||
$variables['region_attributes']['top']->addClass($css_class);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// function eql_preprocess_views_view_unformatted(&$variables) {
|
||||
// // On utilise le service de translittération de Drupal
|
||||
// $transliterator = \Drupal::service('transliteration');
|
||||
|
||||
// foreach ($variables['rows'] as &$row) {
|
||||
// if (isset($row['content']['#node'])) {
|
||||
// $node = $row['content']['#node'];
|
||||
|
||||
// if ($node->hasField('field_type_de_ressource') && !$node->get('field_type_de_ressource')->isEmpty()) {
|
||||
// foreach ($node->get('field_type_de_ressource')->referencedEntities() as $term) {
|
||||
// $label = $term->label();
|
||||
|
||||
// // Supprimer les accents
|
||||
// $label_ascii = $transliterator->transliterate($label);
|
||||
|
||||
// // Nettoyer pour que ce soit une classe CSS valide
|
||||
// $class = 'type-' . Html::cleanCssIdentifier(strtolower($label_ascii));
|
||||
|
||||
// $row['attributes']->addClass($class);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
function eql_preprocess_views_view_unformatted(array &$variables) {
|
||||
$view = $variables['view'];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user