Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 KB | None | 0 0
  1. /**
  2.  * Implements hook_views_pre_render
  3.  * @param \Drupal\views\ViewExecutable $view
  4.  */
  5. function gefic_programs_views_pre_render(\Drupal\views\ViewExecutable $view) {
  6.   if($view->id() == 'programmes' && !empty($view->args)) {
  7.     $termsTree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('departement');
  8.     // Get term by name
  9.     foreach($termsTree as $termDpt) {
  10.       if(\Drupal::service('pathauto.alias_cleaner')->cleanString($termDpt->name) == $view->args[0])
  11.       {
  12.         $term = $termDpt;
  13.       }
  14.     }
  15.  
  16.     if($term) {
  17.       $term = \Drupal\taxonomy\Entity\Term::load($term->tid);
  18.       // Force page title
  19.       $newTitle = 'Nos programmes immobiliers : ' . $term->getName();
  20.       $view->setTitle($newTitle);
  21.  
  22.       $request = \Drupal::request();
  23.       if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
  24.         $route->setDefault('_title', $newTitle);
  25.       }
  26.     }
  27.   }
  28. }
  29.  
  30. $termsTree = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree('departement');
  31.  
  32.     foreach($termsTree as $termDpt) {
  33.       if(\Drupal::service('pathauto.alias_cleaner')->cleanString($termDpt->name) == $params['arg_0'])
  34.       {
  35.         $term = $termDpt;
  36.       }
  37.     }
  38.  
  39.     if($term) {
  40.       $term = \Drupal\taxonomy\Entity\Term::load($term->tid);
  41.  
  42.       $description = [
  43.           '#tag' => 'meta',
  44.           '#attributes' => [
  45.               'name' => 'description',
  46.               'content' => $term->label(),
  47.           ],
  48.       ];
  49.  
  50.       $variables['page']['#attached']['html_head'][] = [$description, 'description'];
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement