array( 'render element' => 'elements', ), ); } /** * Returns whether the current page is the page of the passed-in blog. * * @param \Drupal\dr8_zth\Entity\Blog $blog * A blog entity. * * @return bool * Is the current route the canonical route for the blog ? */ function dr8_zth_blog_is_page(Blog $blog) { if (\Drupal::routeMatch()->getRouteName() == 'entity.blog.canonical' && $page_blog_id = \Drupal::routeMatch()->getRawParameter('blog')) { return $page_blog_id == $blog->id(); } return FALSE; } /** * Implements hook_preprocess_blog(). */ function template_preprocess_blog(&$variables) { // Raise deep information to the root. $variables['view_mode'] = $variables['elements']['#view_mode']; $variables['blog'] = $variables['elements']['#blog']; /** @var \Drupal\dr8_zth\BlogInterface $blog */ $blog = $variables['blog']; $variables['url'] = $blog->toUrl()->toString(); // We use name here because that is what appears in the UI. $variables['title'] = $variables['elements']['title']; unset($variables['elements']['title']); $variables['page'] = $variables['view_mode'] == 'full' && dr8_zth_blog_is_page($blog); // Helpful $content variable for templates. $variables['content'] = array(); foreach (Element::children($variables['elements']) as $key) { $variables['content'][$key] = $variables['elements'][$key]; } }