Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Implements hook_views_pre_render
- * @param \Drupal\views\ViewExecutable $view
- */
- function gefic_programs_views_pre_render(\Drupal\views\ViewExecutable $view) {
- if($view->id() == 'programmes' && !empty($view->args)) {
- $termsTree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('departement');
- // Get term by name
- foreach($termsTree as $termDpt) {
- if(\Drupal::service('pathauto.alias_cleaner')->cleanString($termDpt->name) == $view->args[0])
- {
- $term = $termDpt;
- }
- }
- if($term) {
- $term = \Drupal\taxonomy\Entity\Term::load($term->tid);
- // Force page title
- $newTitle = 'Nos programmes immobiliers : ' . $term->getName();
- $view->setTitle($newTitle);
- $request = \Drupal::request();
- if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
- $route->setDefault('_title', $newTitle);
- }
- }
- }
- }
- $termsTree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('departement');
- foreach($termsTree as $termDpt) {
- if(\Drupal::service('pathauto.alias_cleaner')->cleanString($termDpt->name) == $params['arg_0'])
- {
- $term = $termDpt;
- }
- }
- if($term) {
- $term = \Drupal\taxonomy\Entity\Term::load($term->tid);
- $description = [
- '#tag' => 'meta',
- '#attributes' => [
- 'name' => 'description',
- 'content' => $term->label(),
- ],
- ];
- $variables['page']['#attached']['html_head'][] = [$description, 'description'];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement