region suggestions fix

This commit is contained in:
Bachir Soussi Chiadmi 2024-04-26 18:08:25 +02:00
parent fe03cbe40f
commit dec98f68d4
1 changed files with 25 additions and 7 deletions

View File

@ -114,12 +114,30 @@ function erabletheme_theme_suggestions_node_alter(array &$suggestions, array $va
}
function erabletheme_theme_suggestions_region_alter(array &$suggestions, array $variables) {
// if (isset($variables['elements']['erabletheme_contenudelapageprincipale']) && $variables['elements']['erabletheme_contenudelapageprincipale']['content']['#title'] == "Meet-up en ligne") {
if (isset($variables['elements']['erabletheme_contenudelapageprincipale'])) {
// il ne faut pas baser le template sur des contenus !
if (isset($variables['elements']['erabletheme_contenudelapageprincipale'])
&& $variables['elements']['erabletheme_contenudelapageprincipale']['content']['#view_id'] == "meetup") {
$suggestions[] = 'region__offre_meetup';
} elseif (isset($variables['elements']['erabletheme_contenudelapageprincipale']) && $variables['elements']['erabletheme_contenudelapageprincipale']['content']['#title'] == "Foire aux Questions") {
// if ($variables['elements']['erabletheme_contenudelapageprincipale']['content']['#title'] == "Meet-up en ligne") {
// $suggestions[] = 'region__offre_meetup';
// } else
// if ($variables['elements']['erabletheme_contenudelapageprincipale']['content']['#title'] == "Foire aux Questions") {
// $suggestions[] = 'region__faq';
// }
// ça c'est mieux, se baser uniquement sur des infos structurelles (qui ne sont pas dynamiques)
$routematch = \Drupal::routeMatch();
$routename = $routematch->getRouteName();
switch ($routename) {
case 'faq.faq-page':
$suggestions[] = 'region__faq';
break;
case 'entity.node.canonical':
/** @var \Drupal\node\Entity\Node $node */
$node = $routematch->getParameter('node');
if ($node->getType() === 'offre') {
$suggestions[] = 'region__offre_meetup';
}
break;
}
}
}