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


PHP DisplayPluginBase::buildBasicRenderable方法代码示例

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


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

示例1: testRenderCaching

 /**
  * Tests access on render caching.
  */
 public function testRenderCaching()
 {
     $view = Views::getView('test_access_perm');
     $display =& $view->storage->getDisplay('default');
     $display['display_options']['cache'] = ['type' => 'tag'];
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     /** @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
     $account_switcher = \Drupal::service('account_switcher');
     // First access as user without access.
     $build = DisplayPluginBase::buildBasicRenderable('test_access_perm', 'default');
     $account_switcher->switchTo($this->normalUser);
     $result = $renderer->renderPlain($build);
     $this->assertNotEqual($result, '');
     // Then with access.
     $build = DisplayPluginBase::buildBasicRenderable('test_access_perm', 'default');
     $account_switcher->switchTo($this->webUser);
     $result = $renderer->renderPlain($build);
     $this->assertEqual($result, '');
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:23,代码来源:AccessPermissionTest.php

示例2: testCacheOutputOnPage

 /**
  * Tests the output caching on an actual page.
  */
 public function testCacheOutputOnPage()
 {
     $view = Views::getView('test_display');
     $view->storage->setStatus(TRUE);
     $view->setDisplay('page_1');
     $view->display_handler->overrideOption('cache', array('type' => 'time', 'options' => array('results_lifespan' => '3600', 'output_lifespan' => '3600')));
     $view->save();
     $this->container->get('router.builder')->rebuildIfNeeded();
     /** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
     $render_cache = \Drupal::service('render_cache');
     $cache_element = DisplayPluginBase::buildBasicRenderable('test_display', 'page_1');
     $cache_element['#cache'] += ['contexts' => $this->container->getParameter('renderer.config')['required_cache_contexts']];
     $this->assertFalse($render_cache->get($cache_element));
     $this->drupalGet('test-display');
     $this->assertResponse(200);
     $this->assertTrue($render_cache->get($cache_element));
     $cache_tags = ['config:user.role.anonymous', 'config:views.view.test_display', 'node_list', 'rendered'];
     $this->assertCacheTags($cache_tags);
     $this->drupalGet('test-display');
     $this->assertResponse(200);
     $this->assertTrue($render_cache->get($cache_element));
     $this->assertCacheTags($cache_tags);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:26,代码来源:CacheWebTest.php

示例3: testRestRenderCaching

 /**
  * Tests REST export with views render caching enabled.
  */
 public function testRestRenderCaching()
 {
     $this->drupalLogin($this->adminUser);
     /** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
     $render_cache = \Drupal::service('render_cache');
     // Enable render caching for the views.
     /** @var \Drupal\views\ViewEntityInterface $storage */
     $storage = View::load('test_serializer_display_entity');
     $options =& $storage->getDisplay('default');
     $options['display_options']['cache'] = ['type' => 'tag'];
     $storage->save();
     $original = DisplayPluginBase::buildBasicRenderable('test_serializer_display_entity', 'rest_export_1');
     // Ensure that there is no corresponding render cache item yet.
     $original['#cache'] += ['contexts' => []];
     $original['#cache']['contexts'] = Cache::mergeContexts($original['#cache']['contexts'], $this->container->getParameter('renderer.config')['required_cache_contexts']);
     $cache_tags = ['config:views.view.test_serializer_display_entity', 'entity_test:1', 'entity_test:10', 'entity_test:2', 'entity_test:3', 'entity_test:4', 'entity_test:5', 'entity_test:6', 'entity_test:7', 'entity_test:8', 'entity_test:9', 'entity_test_list'];
     $cache_contexts = ['entity_test_view_grants', 'languages:language_interface', 'theme', 'request_format'];
     $this->assertFalse($render_cache->get($original));
     // Request the page, once in XML and once in JSON to ensure that the caching
     // varies by it.
     $result1 = $this->drupalGetJSON('test/serialize/entity');
     $this->addRequestWithFormat('json');
     $this->assertHeader('content-type', 'application/json');
     $this->assertCacheContexts($cache_contexts);
     $this->assertCacheTags($cache_tags);
     $this->assertTrue($render_cache->get($original));
     $result_xml = $this->drupalGetWithFormat('test/serialize/entity', 'xml');
     $this->addRequestWithFormat('xml');
     $this->assertHeader('content-type', 'text/xml; charset=UTF-8');
     $this->assertCacheContexts($cache_contexts);
     $this->assertCacheTags($cache_tags);
     $this->assertTrue($render_cache->get($original));
     // Ensure that the XML output is different from the JSON one.
     $this->assertNotEqual($result1, $result_xml);
     // Ensure that the cached page works.
     $result2 = $this->drupalGetJSON('test/serialize/entity');
     $this->addRequestWithFormat('json');
     $this->assertHeader('content-type', 'application/json');
     $this->assertEqual($result2, $result1);
     $this->assertCacheContexts($cache_contexts);
     $this->assertCacheTags($cache_tags);
     $this->assertTrue($render_cache->get($original));
     // Create a new entity and ensure that the cache tags are taken over.
     EntityTest::create(['name' => 'test_11', 'user_id' => $this->adminUser->id()])->save();
     $result3 = $this->drupalGetJSON('test/serialize/entity');
     $this->addRequestWithFormat('json');
     $this->assertHeader('content-type', 'application/json');
     $this->assertNotEqual($result3, $result2);
     // Add the new entity cache tag and remove the first one, because we just
     // show 10 items in total.
     $cache_tags[] = 'entity_test:11';
     unset($cache_tags[array_search('entity_test:1', $cache_tags)]);
     $this->assertCacheContexts($cache_contexts);
     $this->assertCacheTags($cache_tags);
     $this->assertTrue($render_cache->get($original));
 }
开发者ID:318io,项目名称:318-io,代码行数:59,代码来源:StyleSerializerTest.php

示例4: testRandomOrderingWithRenderCaching

 /**
  * Tests random ordering with tags based caching.
  *
  * The random sorting should opt out of caching by defining a max age of 0.
  * At the same time, the row render caching still works.
  */
 public function testRandomOrderingWithRenderCaching()
 {
     $view_random = $this->getBasicRandomView();
     $display =& $view_random->storage->getDisplay('default');
     $display['display_options']['cache'] = ['type' => 'tag'];
     $view_random->storage->save();
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     /** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
     $render_cache = \Drupal::service('render_cache');
     $original = $build = DisplayPluginBase::buildBasicRenderable($view_random->id(), 'default');
     $result = $renderer->renderPlain($build);
     $original['#cache'] += ['contexts' => []];
     $original['#cache']['contexts'] = Cache::mergeContexts($original['#cache']['contexts'], $this->container->getParameter('renderer.config')['required_cache_contexts']);
     $this->assertFalse($render_cache->get($original), 'Ensure there is no render cache entry.');
     $build = DisplayPluginBase::buildBasicRenderable($view_random->id(), 'default');
     $result2 = $renderer->renderPlain($build);
     // Ensure that the random ordering works and don't produce the same result.
     $this->assertNotEqual($result, $result2);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:26,代码来源:SortRandomTest.php

示例5: assertViewsCacheTagsFromStaticRenderArray

 /**
  * Asserts a view's result & render cache items' cache tags.
  *
  * This method starts with a pre bubbling basic render array.
  *
  * @param \Drupal\views\ViewExecutable $view
  *   The view.
  * @param string[] $expected_render_array_cache_tags
  *   The expected render cache tags.
  * @param bool $views_caching_is_enabled
  *   Defines whether views output / render caching is enabled.
  *
  * @return array
  *   The render array.
  */
 protected function assertViewsCacheTagsFromStaticRenderArray(ViewExecutable $view, array $expected_render_array_cache_tags, $views_caching_is_enabled)
 {
     $original = $build = DisplayPluginBase::buildBasicRenderable($view->id(), $view->current_display ?: 'default', $view->args);
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     /** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
     $render_cache = \Drupal::service('render_cache');
     // 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);
     $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);
     $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) {
         $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.');
     }
     return $build;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:50,代码来源:AssertViewsCacheTagsTrait.php

示例6: testRenderCaching

 /**
  * Tests access on render caching.
  */
 public function testRenderCaching()
 {
     $view = Views::getView('test_access_role');
     $display =& $view->storage->getDisplay('default');
     $display['display_options']['cache'] = ['type' => 'tag'];
     $display['display_options']['access']['options']['role'] = array($this->normalRole => $this->normalRole);
     $view->save();
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     /** @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
     $account_switcher = \Drupal::service('account_switcher');
     // First access as user with access.
     $build = DisplayPluginBase::buildBasicRenderable('test_access_role', 'default');
     $account_switcher->switchTo($this->normalUser);
     $result = $renderer->renderPlain($build);
     $this->assertTrue(in_array('user.roles', $build['#cache']['contexts']));
     $this->assertEqual(['config:views.view.test_access_role'], $build['#cache']['tags']);
     $this->assertEqual(Cache::PERMANENT, $build['#cache']['max-age']);
     $this->assertNotEqual($result, '');
     // Then without access.
     $build = DisplayPluginBase::buildBasicRenderable('test_access_role', 'default');
     $account_switcher->switchTo($this->webUser);
     $result = $renderer->renderPlain($build);
     // @todo Fix this in https://www.drupal.org/node/2551037,
     // DisplayPluginBase::applyDisplayCachablityMetadata() is not invoked when
     // using buildBasicRenderable() and a Views access plugin returns FALSE.
     //$this->assertTrue(in_array('user.roles', $build['#cache']['contexts']));
     //$this->assertEqual([], $build['#cache']['tags']);
     $this->assertEqual(Cache::PERMANENT, $build['#cache']['max-age']);
     $this->assertEqual($result, '');
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:34,代码来源:AccessRoleTest.php


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