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


PHP ViewExecutable::setRequest方法代码示例

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


在下文中一共展示了ViewExecutable::setRequest方法的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: get

 /**
  * Instantiates a ViewExecutable class.
  *
  * @param \Drupal\views\ViewStorageInterface $view
  *   A view entity instance.
  *
  * @return \Drupal\views\ViewExecutable
  *   A ViewExecutable instance.
  */
 public function get(ViewStorageInterface $view)
 {
     $view = new ViewExecutable($view, $this->user);
     $view->setRequest($this->requestStack->getCurrentRequest());
     return $view;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:15,代码来源:ViewExecutableFactory.php

示例3: get

 /**
  * Instantiates a ViewExecutable class.
  *
  * @param \Drupal\views\ViewEntityInterface $view
  *   A view entity instance.
  *
  * @return \Drupal\views\ViewExecutable
  *   A ViewExecutable instance.
  */
 public function get(ViewEntityInterface $view)
 {
     $view = new ViewExecutable($view, $this->user, $this->viewsData, $this->routeProvider);
     $view->setRequest($this->requestStack->getCurrentRequest());
     return $view;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:15,代码来源:ViewExecutableFactory.php


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