Exemplo n.º 1
0
 /**
  * Converts a render array into an HtmlFragment object.
  *
  * @param array|\Drupal\Core\Page\HtmlFragmentInterface|\Symfony\Component\HttpFoundation\Response $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.
  *
  * @throws \InvalidArgumentException
  *   Thrown if the controller returns a string.
  */
 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_string($page_content)) {
         throw new \InvalidArgumentException('_content controllers are not allowed to return strings. You can return a render array, a html fragment or a response object.');
     }
     $fragment = $this->renderHtmlRenderer->render($page_content);
     if (!$fragment->getTitle() && ($route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT))) {
         $fragment->setTitle($this->titleResolver->getTitle($request, $route), Title::PASS_THROUGH);
     }
     return $fragment;
 }
 /**
  * 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 = ['#markup' => $page_content];
     }
     $fragment = $this->renderHtmlRenderer->render($page_content);
     if (!$fragment->getTitle() && ($route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT))) {
         $fragment->setTitle($this->titleResolver->getTitle($request, $route), Title::PASS_THROUGH);
     }
     return $fragment;
 }