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


PHP ViewExecutable::buildRenderable方法代码示例

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


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

示例1: assertViewsCacheTags

 /**
  * Asserts a view's result & render cache items' cache tags.
  *
  * This methods uses a full view object in order to render the view.
  *
  * @param \Drupal\views\ViewExecutable $view
  *   The view to test, must have caching enabled.
  * @param null|string[] $expected_results_cache
  *   NULL when expecting no results cache item, a set of cache tags expected
  *   to be set on the results cache item otherwise.
  * @param bool $views_caching_is_enabled
  *   Whether to expect an output cache item. If TRUE, the cache tags must
  *   match those in $expected_render_array_cache_tags.
  * @param string[] $expected_render_array_cache_tags
  *   A set of cache tags expected to be set on the built view's render array.
  *
  * @return array
  *   The render array.
  */
 protected function assertViewsCacheTags(ViewExecutable $view, $expected_results_cache, $views_caching_is_enabled, array $expected_render_array_cache_tags)
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     /** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
     $render_cache = \Drupal::service('render_cache');
     $build = $view->buildRenderable();
     $original = $build;
     // Ensure the current request is a GET request so that render caching is
     // active for direct rendering of views, just like for actual requests.
     /** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */
     $request_stack = \Drupal::service('request_stack');
     $request = new Request();
     $request->server->set('REQUEST_TIME', REQUEST_TIME);
     $view->setRequest($request);
     $request_stack->push($request);
     $renderer->renderRoot($build);
     // Render array cache tags.
     $this->pass('Checking render array cache tags.');
     sort($expected_render_array_cache_tags);
     $this->assertEqual($build['#cache']['tags'], $expected_render_array_cache_tags);
     $this->debugCacheTags($build['#cache']['tags'], $expected_render_array_cache_tags);
     if ($views_caching_is_enabled) {
         $this->pass('Checking Views results cache item cache tags.');
         /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache_plugin */
         $cache_plugin = $view->display_handler->getPlugin('cache');
         // Results cache.
         // Ensure that the views query is built.
         $view->build();
         $results_cache_item = \Drupal::cache('data')->get($cache_plugin->generateResultsKey());
         if (is_array($expected_results_cache)) {
             $this->assertTrue($results_cache_item, 'Results cache item found.');
             if ($results_cache_item) {
                 sort($expected_results_cache);
                 $this->assertEqual($results_cache_item->tags, $expected_results_cache);
                 $this->debugCacheTags($results_cache_item->tags, $expected_results_cache);
             }
         } else {
             $this->assertFalse($results_cache_item, 'Results cache item not found.');
         }
         $this->pass('Checking Views render cache item cache tags.');
         $original['#cache'] += ['contexts' => []];
         $original['#cache']['contexts'] = Cache::mergeContexts($original['#cache']['contexts'], $this->container->getParameter('renderer.config')['required_cache_contexts']);
         $render_cache_item = $render_cache->get($original);
         if ($views_caching_is_enabled === TRUE) {
             $this->assertTrue(!empty($render_cache_item), 'Render cache item found.');
             if ($render_cache_item) {
                 $this->assertEqual($render_cache_item['#cache']['tags'], $expected_render_array_cache_tags);
                 $this->debugCacheTags($render_cache_item['#cache']['tags'], $expected_render_array_cache_tags);
             }
         } else {
             $this->assertFalse($render_cache_item, 'Render cache item not found.');
         }
     }
     $view->destroy();
     $request_stack->pop();
     return $build;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:77,代码来源:AssertViewsCacheTagsTrait.php

示例2: getRenderCache

 /**
  * Gets the render cache for a given view.
  *
  * @param \Drupal\views\ViewExecutable $view
  *   The view.
  *
  * @return array|FALSE
  *   The render cache result or FALSE if not existent.
  */
 protected function getRenderCache(ViewExecutable $view)
 {
     /** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
     $render_cache = \Drupal::service('render_cache');
     $view->element = ['#cache' => []];
     $build = $view->buildRenderable();
     $build['#cache']['contexts'] = Cache::mergeContexts($build['#cache']['contexts'], $this->container->getParameter('renderer.config')['required_cache_contexts']);
     return $render_cache->get($build);
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:18,代码来源:CacheTagTest.php

示例3: attachTo

 /**
  * {@inheritdoc}
  */
 public function attachTo(ViewExecutable $view, $display_id, array &$build)
 {
     $displays = $this->getOption('displays');
     if (empty($displays[$display_id])) {
         return;
     }
     if (!$this->access()) {
         return;
     }
     $args = $this->getOption('inherit_arguments') ? $this->view->args : array();
     $view->setArguments($args);
     $view->setDisplay($this->display['id']);
     if ($this->getOption('inherit_pager')) {
         $view->display_handler->usesPager = $this->view->displayHandlers->get($display_id)->usesPager();
         $view->display_handler->setOption('pager', $this->view->displayHandlers->get($display_id)->getOption('pager'));
     }
     $attachment = $view->buildRenderable($this->display['id'], $args);
     switch ($this->getOption('attachment_position')) {
         case 'before':
             $this->view->attachment_before[] = $attachment;
             break;
         case 'after':
             $this->view->attachment_after[] = $attachment;
             break;
         case 'both':
             $this->view->attachment_before[] = $attachment;
             $this->view->attachment_after[] = $attachment;
             break;
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:33,代码来源:Attachment.php


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