filters on archive pages, type de projet & type devenemtn now linked to filtered archive views
This commit is contained in:
@@ -50,6 +50,45 @@ function leshed_preprocess_page(&$variables) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Rend le titre de base cliquable vers la vue non filtrée sur les pages
|
||||
* /projets/{term} et /evenements/{term}. Le titre de la vue est "Les Projets"
|
||||
* ou "Les Événements | Concert" : on sépare sur " | " et on rend la première
|
||||
* partie en lien vers /projets ou /evenements.
|
||||
*/
|
||||
function leshed_preprocess_page_title(&$variables) {
|
||||
$route_name = \Drupal::routeMatch()->getRouteName();
|
||||
$base_paths = [
|
||||
'view.archives.page_1' => '/projets',
|
||||
'view.archives.page_2' => '/evenements',
|
||||
];
|
||||
if (!isset($base_paths[$route_name])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$title = $variables['title'] ?? '';
|
||||
if (is_array($title)) {
|
||||
$title = \Drupal::service('renderer')->render($title);
|
||||
}
|
||||
$title = (string) $title;
|
||||
if (empty($title)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$parts = explode(' | ', $title, 2);
|
||||
if (count($parts) < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$base_title = $parts[0];
|
||||
$term_part = $parts[1];
|
||||
$base_url = \Drupal\Core\Url::fromUserInput($base_paths[$route_name]);
|
||||
|
||||
$variables['title'] = [
|
||||
'#markup' => '<a href="' . $base_url->toString() . '">' . \Drupal\Component\Utility\Html::escape($base_title) . '</a> | ' . \Drupal\Component\Utility\Html::escape($term_part),
|
||||
];
|
||||
}
|
||||
|
||||
function leshed_preprocess_region(&$variables) {
|
||||
if (!isset($variables["attributes"]['class'])) {
|
||||
$variables["attributes"]['class'] = [];
|
||||
@@ -152,6 +191,38 @@ function leshed_preprocess_field(&$variables) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Réécrit les liens des termes type_de_projet vers la vue projets filtrée
|
||||
// par filtre contextuel. Drupal résout automatiquement l'alias
|
||||
// (/projets/1 -> /projets/expo) depuis la table path_alias.
|
||||
if ($variables['field_name'] === 'field_type_de_projet') {
|
||||
foreach ($variables['items'] as &$item) {
|
||||
$content = &$item['content'];
|
||||
if (isset($content['#type']) && $content['#type'] === 'link' && isset($content['#url'])) {
|
||||
/** @var \Drupal\taxonomy\TermInterface $term */
|
||||
$term = $content['#entity'] ?? NULL;
|
||||
if ($term && $term->bundle() === 'type_de_projet') {
|
||||
$content['#url'] = \Drupal\Core\Url::fromUserInput('/projets/' . $term->id());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Réécrit les liens des termes type_d_evenement vers la vue evenements
|
||||
// filtrée par filtre contextuel. Drupal résout automatiquement l'alias
|
||||
// (/evenements/14 -> /evenements/concert) depuis la table path_alias.
|
||||
if ($variables['field_name'] === 'field_type_d_evenement') {
|
||||
foreach ($variables['items'] as &$item) {
|
||||
$content = &$item['content'];
|
||||
if (isset($content['#type']) && $content['#type'] === 'link' && isset($content['#url'])) {
|
||||
/** @var \Drupal\taxonomy\TermInterface $term */
|
||||
$term = $content['#entity'] ?? NULL;
|
||||
if ($term && $term->bundle() === 'type_d_evenement') {
|
||||
$content['#url'] = \Drupal\Core\Url::fromUserInput('/evenements/' . $term->id());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function leshed_preprocess_links__language_block(&$variables){
|
||||
|
||||
Reference in New Issue
Block a user