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


PHP BubbleableMetadata::setCacheContexts方法代码示例

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


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

示例1: providerTestCreateFromRenderArray

 /**
  * Provides test data for createFromRenderArray().
  *
  * @return array
  */
 public function providerTestCreateFromRenderArray()
 {
     $data = [];
     $empty_metadata = new BubbleableMetadata();
     $nonempty_metadata = new BubbleableMetadata();
     $nonempty_metadata->setCacheContexts(['qux'])->setCacheTags(['foo:bar'])->setAssets(['settings' => ['foo' => 'bar']]);
     $empty_render_array = [];
     $nonempty_render_array = ['#cache' => ['contexts' => ['qux'], 'tags' => ['foo:bar'], 'max-age' => Cache::PERMANENT], '#attached' => ['settings' => ['foo' => 'bar']], '#post_render_cache' => []];
     $data[] = [$empty_render_array, $empty_metadata];
     $data[] = [$nonempty_render_array, $nonempty_metadata];
     return $data;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:17,代码来源:BubbleableMetadataTest.php

示例2: processOutbound

 public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL)
 {
     if (array_key_exists('purl_context', $options) && $options['purl_context'] == false) {
         if (count($this->matchedModifiers->getMatched()) && $bubbleable_metadata) {
             $cacheContexts = $bubbleable_metadata->getCacheContexts();
             $cacheContexts[] = 'purl';
             $bubbleable_metadata->setCacheContexts($cacheContexts);
         }
         return $this->contextHelper->processOutbound($this->matchedModifiers->createContexts(Context::EXIT_CONTEXT), $path, $options, $request, $bubbleable_metadata);
     }
     return $this->contextHelper->processOutbound($this->matchedModifiers->createContexts(), $path, $options, $request, $bubbleable_metadata);
 }
开发者ID:activelamp,项目名称:purl-d8,代码行数:12,代码来源:PurlContextOutboundPathProcessor.php

示例3: testPathPrefix

 /**
  * Test path prefix language negotiation and outbound path processing.
  *
  * @dataProvider providerTestPathPrefix
  */
 public function testPathPrefix($prefix, $prefixes, $expected_langcode)
 {
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->will($this->returnValue($this->languages[in_array($expected_langcode, ['en', 'de']) ? $expected_langcode : 'en']));
     $config = $this->getConfigFactoryStub(['language.negotiation' => ['url' => ['source' => LanguageNegotiationUrl::CONFIG_PATH_PREFIX, 'prefixes' => $prefixes]]]);
     $request = Request::create('/' . $prefix . '/foo', 'GET');
     $method = new LanguageNegotiationUrl();
     $method->setLanguageManager($this->languageManager);
     $method->setConfig($config);
     $method->setCurrentUser($this->user);
     $this->assertEquals($expected_langcode, $method->getLangcode($request));
     $cacheability = new BubbleableMetadata();
     $options = [];
     $method->processOutbound('foo', $options, $request, $cacheability);
     $expected_cacheability = new BubbleableMetadata();
     if ($expected_langcode) {
         $this->assertSame($prefix . '/', $options['prefix']);
         $expected_cacheability->setCacheContexts(['languages:' . LanguageInterface::TYPE_URL]);
     } else {
         $this->assertFalse(isset($options['prefix']));
     }
     $this->assertEquals($expected_cacheability, $cacheability);
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:27,代码来源:LanguageNegotiationUrlTest.php

示例4: testReplaceWithHookTokensAlterWithBubbleableMetadata

 /**
  * @covers ::replace
  * @covers ::replace
  */
 public function testReplaceWithHookTokensAlterWithBubbleableMetadata()
 {
     $this->moduleHandler->expects($this->any())->method('invokeAll')->willReturn([]);
     $this->moduleHandler->expects($this->any())->method('alter')->willReturnCallback(function ($hook_name, array &$replacements, array $context, BubbleableMetadata $bubbleable_metadata) {
         $replacements['[node:title]'] = 'hello world';
         $bubbleable_metadata->addCacheContexts(['custom_context']);
         $bubbleable_metadata->addCacheTags(['node:1']);
         $bubbleable_metadata->setCacheMaxAge(10);
     });
     $node = $this->prophesize('Drupal\\node\\NodeInterface');
     $node->getCacheContexts()->willReturn([]);
     $node->getCacheTags()->willReturn([]);
     $node->getCacheMaxAge()->willReturn(14);
     $node = $node->reveal();
     $bubbleable_metadata = new BubbleableMetadata();
     $bubbleable_metadata->setCacheContexts(['current_user']);
     $bubbleable_metadata->setCacheMaxAge(12);
     $result = $this->token->replace('[node:title]', ['node' => $node], [], $bubbleable_metadata);
     $this->assertEquals('hello world', $result);
     $this->assertEquals(['node:1'], $bubbleable_metadata->getCacheTags());
     $this->assertEquals(['current_user', 'custom_context'], $bubbleable_metadata->getCacheContexts());
     $this->assertEquals(10, $bubbleable_metadata->getCacheMaxAge());
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:27,代码来源:TokenTest.php


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