当前位置: 首页>>代码示例>>PHP>>正文


PHP RendererInterface::getCacheableRenderArray方法代码示例

本文整理汇总了PHP中Drupal\Core\Render\RendererInterface::getCacheableRenderArray方法的典型用法代码示例。如果您正苦于以下问题:PHP RendererInterface::getCacheableRenderArray方法的具体用法?PHP RendererInterface::getCacheableRenderArray怎么用?PHP RendererInterface::getCacheableRenderArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Render\RendererInterface的用法示例。


在下文中一共展示了RendererInterface::getCacheableRenderArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: cacheSet

 /**
  * Save data to the cache.
  *
  * A plugin should override this to provide specialized caching behavior.
  */
 public function cacheSet($type)
 {
     switch ($type) {
         case 'query':
             // Not supported currently, but this is certainly where we'd put it.
             break;
         case 'results':
             $data = array('result' => $this->prepareViewResult($this->view->result), 'total_rows' => isset($this->view->total_rows) ? $this->view->total_rows : 0, 'current_page' => $this->view->getCurrentPage());
             \Drupal::cache($this->resultsBin)->set($this->generateResultsKey(), $data, $this->cacheSetExpire($type), $this->getCacheTags());
             break;
         case 'output':
             // Make a copy of the output so it is not modified. If we render the
             // display output directly an empty string will be returned when the
             // view is actually rendered. If we try to set '#printed' to FALSE there
             // are problems with asset bubbling.
             $output = $this->view->display_handler->output;
             $this->renderer->render($output);
             // Also assign the cacheable render array back to the display handler so
             // that is used to render the view for this request and rendering does
             // not happen twice.
             $this->storage = $this->view->display_handler->output = $this->renderer->getCacheableRenderArray($output);
             \Drupal::cache($this->outputBin)->set($this->generateOutputKey(), $this->storage, $this->cacheSetExpire($type), Cache::mergeTags($this->storage['#cache']['tags'], ['rendered']));
             break;
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:30,代码来源:CachePluginBase.php

示例2: prepare

 /**
  * Prepares the HTML body: wraps the main content in #type 'page'.
  *
  * @param array $main_content
  *   The render array representing the main content.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object, for context.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match, for context.
  *
  * @return array
  *   An array with two values:
  *   0. A #type 'page' render array.
  *   1. The page title.
  *
  * @throws \LogicException
  *   If the selected display variant does not implement PageVariantInterface.
  */
 protected function prepare(array $main_content, Request $request, RouteMatchInterface $route_match)
 {
     // If the _controller result already is #type => page,
     // we have no work to do: The "main content" already is an entire "page"
     // (see html.html.twig).
     if (isset($main_content['#type']) && $main_content['#type'] === 'page') {
         $page = $main_content;
     } else {
         // Select the page display variant to be used to render this main content,
         // default to the built-in "simple page".
         $event = new PageDisplayVariantSelectionEvent('simple_page', $route_match);
         $this->eventDispatcher->dispatch(RenderEvents::SELECT_PAGE_DISPLAY_VARIANT, $event);
         $variant_id = $event->getPluginId();
         // We must render the main content now already, because it might provide a
         // title. We set its $is_root_call parameter to FALSE, to ensure
         // #post_render_cache callbacks are not yet applied. This is essentially
         // "pre-rendering" the main content, the "full rendering" will happen in
         // ::renderResponse().
         // @todo Remove this once https://www.drupal.org/node/2359901 lands.
         if (!empty($main_content)) {
             $this->renderer->render($main_content, FALSE);
             $main_content = $this->renderer->getCacheableRenderArray($main_content) + ['#title' => isset($main_content['#title']) ? $main_content['#title'] : NULL];
         }
         // Instantiate the page display, and give it the main content.
         $page_display = $this->displayVariantManager->createInstance($variant_id);
         if (!$page_display instanceof PageVariantInterface) {
             throw new \LogicException('Cannot render the main content for this page because the provided display variant does not implement PageVariantInterface.');
         }
         $page_display->setMainContent($main_content);
         // Generate a #type => page render array using the page display variant,
         // the page display will build the content for the various page regions.
         $page = array('#type' => 'page');
         $page += $page_display->build();
     }
     // $page is now fully built. Find all non-empty page regions, and add a
     // theme wrapper function that allows them to be consistently themed.
     $regions = system_region_list(\Drupal::theme()->getActiveTheme()->getName());
     foreach (array_keys($regions) as $region) {
         if (!empty($page[$region])) {
             $page[$region]['#theme_wrappers'][] = 'region';
             $page[$region]['#region'] = $region;
         }
     }
     // Allow hooks to add attachments to $page['#attached'].
     $this->invokePageAttachmentHooks($page);
     // Determine the title: use the title provided by the main content if any,
     // otherwise get it from the routing information.
     $title = isset($main_content['#title']) ? $main_content['#title'] : $this->titleResolver->getTitle($request, $route_match->getRouteObject());
     return [$page, $title];
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:68,代码来源:HtmlRenderer.php


注:本文中的Drupal\Core\Render\RendererInterface::getCacheableRenderArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。