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


PHP BubbleableMetadata::addCacheTags方法代码示例

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


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

示例1: processOutbound

 /**
  * Implements Drupal\Core\PathProcessor\OutboundPathProcessorInterface::processOutbound().
  */
 public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL)
 {
     // Rewrite user/uid to user/username.
     if (preg_match('!^/user/([0-9]+)(/.*)?!', $path, $matches)) {
         if ($account = User::load($matches[1])) {
             $matches += array(2 => '');
             $path = '/user/' . $account->getUsername() . $matches[2];
             if ($bubbleable_metadata) {
                 $bubbleable_metadata->addCacheTags($account->getCacheTags());
             }
         }
     }
     // Rewrite forum/ to community/.
     return preg_replace('@^/forum(.*)@', '/community$1', $path);
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:18,代码来源:PathProcessorTest.php

示例2: processOutbound

 /**
  * {@inheritdoc}
  */
 public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL)
 {
     if ($request) {
         // The following values are not supposed to change during a single page
         // request processing.
         if (!isset($this->queryRewrite)) {
             if ($this->currentUser->isAnonymous()) {
                 $languages = $this->languageManager->getLanguages();
                 $config = $this->config->get('language.negotiation')->get('session');
                 $this->queryParam = $config['parameter'];
                 $this->queryValue = $request->query->has($this->queryParam) ? $request->query->get($this->queryParam) : NULL;
                 $this->queryRewrite = isset($languages[$this->queryValue]);
             } else {
                 $this->queryRewrite = FALSE;
             }
         }
         // If the user is anonymous, the user language negotiation method is
         // enabled, and the corresponding option has been set, we must preserve
         // any explicit user language preference even with cookies disabled.
         if ($this->queryRewrite) {
             if (isset($options['query']) && is_string($options['query'])) {
                 $query = array();
                 parse_str($options['query'], $query);
                 $options['query'] = $query;
             }
             if (!isset($options['query'][$this->queryParam])) {
                 $options['query'][$this->queryParam] = $this->queryValue;
             }
             if ($bubbleable_metadata) {
                 // Cached URLs that have been processed by this outbound path
                 // processor must be:
                 $bubbleable_metadata->addCacheTags($this->config->get('language.negotiation')->getCacheTags())->addCacheContexts(['url.query_args:' . $this->queryParam]);
             }
         }
     }
     return $path;
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:40,代码来源:LanguageNegotiationSession.php


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