Ejemplo n.º 1
0
 /**
  * Converts a render array into an HtmlFragment object.
  *
  * @param array|string $page_content
  *   The page content area to display.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  *
  * @return \Drupal\Core\Page\HtmlPage
  *   A page object.
  */
 protected function createHtmlFragment($page_content, Request $request)
 {
     // Allow controllers to return a HtmlFragment or a Response object directly.
     if ($page_content instanceof HtmlFragment || $page_content instanceof Response) {
         return $page_content;
     }
     if (!is_array($page_content)) {
         $page_content = array('main' => array('#markup' => $page_content));
     }
     $content = $this->drupalRender($page_content);
     $cache = !empty($page_content['#cache']['tags']) ? array('tags' => $page_content['#cache']['tags']) : array();
     $fragment = new HtmlFragment($content, $cache);
     // A title defined in the return always wins.
     if (isset($page_content['#title'])) {
         $fragment->setTitle($page_content['#title'], Title::FILTER_XSS_ADMIN);
     } else {
         if ($route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) {
             $fragment->setTitle($this->titleResolver->getTitle($request, $route), Title::PASS_THROUGH);
         }
     }
     // Add feed links from the page content.
     $attached = drupal_render_collect_attached($page_content, TRUE);
     if (!empty($attached['drupal_add_feed'])) {
         foreach ($attached['drupal_add_feed'] as $feed) {
             $feed_link = new FeedLinkElement($feed[1], $this->urlGenerator->generateFromPath($feed[0]));
             $fragment->addLinkElement($feed_link);
         }
     }
     return $fragment;
 }
Ejemplo n.º 2
0
 /**
  * Gather the JS/CSS from the render array, the html head from the band data.
  */
 protected function gatherHeaders()
 {
     // Simple replacement for head
     if (isset($this->storage['head'])) {
         $this->storage['head'] = str_replace($this->storage['head'], '', drupal_add_html_head());
     } else {
         $this->storage['head'] = '';
     }
     $attached = drupal_render_collect_attached($this->storage['output']);
     $this->storage['css'] = $attached['css'];
     $this->storage['js'] = $attached['js'];
 }