/** * {@inheritdoc} */ public function renderBarePage(array $content, $title, $page_theme_property, array $page_additions = []) { $attributes = ['class' => [str_replace('_', '-', $page_theme_property)]]; $html = ['#type' => 'html', '#attributes' => $attributes, 'page' => ['#type' => 'page', '#theme' => $page_theme_property, '#title' => $title, 'content' => $content] + $page_additions]; // For backwards compatibility. // @todo In Drupal 9, add a $show_messages function parameter. if (!isset($page_additions['#show_messages']) || $page_additions['#show_messages'] === TRUE) { $html['page']['messages'] = ['#type' => 'status_messages']; } // We must first render the contents of the html.html.twig template, see // \Drupal\Core\Render\MainContent\HtmlRenderer::renderResponse() for more // information about this; the exact same pattern is used there and // explained in detail there. $this->renderer->render($html['page'], TRUE); // Add the bare minimum of attachments from the system module and the // current maintenance theme. system_page_attachments($html['page']); return $this->renderer->render($html); }
/** * #post_render_cache callback; replaces the placeholder with comment links. * * Renders the links on a comment. * * @param array $element * The renderable array that contains the to be replaced placeholder. * @param array $context * An array with the following keys: * - comment_entity_id: a comment entity ID * - view_mode: the view mode in which the comment entity is being viewed * - langcode: in which language the comment entity is being viewed * - commented_entity_type: the entity type to which the comment is attached * - commented_entity_id: the entity ID to which the comment is attached * - in_preview: whether the comment is currently being previewed * * @return array * A renderable array representing the comment links. */ public function renderLinks(array $element, array $context) { $callback = 'comment.post_render_cache:renderLinks'; $placeholder = $this->generatePlaceholder($callback, $context); $links = array('#theme' => 'links__comment', '#pre_render' => array('drupal_pre_render_links'), '#attributes' => array('class' => array('links', 'inline'))); if (!$context['in_preview']) { /** @var \Drupal\comment\CommentInterface $entity */ $entity = $this->entityManager->getStorage('comment')->load($context['comment_entity_id']); $commented_entity = $entity->getCommentedEntity(); $links['comment'] = $this->buildLinks($entity, $commented_entity); // Allow other modules to alter the comment links. $hook_context = array('view_mode' => $context['view_mode'], 'langcode' => $context['langcode'], 'commented_entity' => $commented_entity); $this->moduleHandler->alter('comment_links', $links, $entity, $hook_context); } $markup = $this->renderer->render($links); $element['#markup'] = str_replace($placeholder, $markup, $element['#markup']); return $element; }