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


PHP BubbleableMetadata::addCacheContexts方法代码示例

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


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

示例1: processOutbound

 /**
  * {@inheritdoc}
  */
 public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL)
 {
     if ($route_name === '<current>') {
         if ($current_route = $this->routeMatch->getRouteObject()) {
             $requirements = $current_route->getRequirements();
             // Setting _method and _schema is deprecated since 2.7. Using
             // setMethods() and setSchemes() are now the recommended ways.
             unset($requirements['_method']);
             unset($requirements['_schema']);
             $route->setRequirements($requirements);
             $route->setPath($current_route->getPath());
             $route->setSchemes($current_route->getSchemes());
             $route->setMethods($current_route->getMethods());
             $route->setOptions($current_route->getOptions());
             $route->setDefaults($current_route->getDefaults());
             $parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
             if ($bubbleable_metadata) {
                 $bubbleable_metadata->addCacheContexts(['route']);
             }
         } else {
             // If we have no current route match available, point to the frontpage.
             $route->setPath('/');
         }
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:28,代码来源:RouteProcessorCurrent.php

示例2: processOutbound

 /**
  * {@inheritdoc}
  */
 public function processOutbound($path, &$options = array(), Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL)
 {
     $url_scheme = 'http';
     $port = 80;
     if ($request) {
         $url_scheme = $request->getScheme();
         $port = $request->getPort();
     }
     $languages = array_flip(array_keys($this->languageManager->getLanguages()));
     // Language can be passed as an option, or we go for current URL language.
     if (!isset($options['language'])) {
         $language_url = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL);
         $options['language'] = $language_url;
     } elseif (!is_object($options['language']) || !isset($languages[$options['language']->getId()])) {
         return $path;
     }
     $config = $this->config->get('language.negotiation')->get('url');
     if ($config['source'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
         if (is_object($options['language']) && !empty($config['prefixes'][$options['language']->getId()])) {
             $options['prefix'] = $config['prefixes'][$options['language']->getId()] . '/';
             if ($bubbleable_metadata) {
                 $bubbleable_metadata->addCacheContexts(['languages:' . LanguageInterface::TYPE_URL]);
             }
         }
     } elseif ($config['source'] == LanguageNegotiationUrl::CONFIG_DOMAIN) {
         if (is_object($options['language']) && !empty($config['domains'][$options['language']->getId()])) {
             // Save the original base URL. If it contains a port, we need to
             // retain it below.
             if (!empty($options['base_url'])) {
                 // The colon in the URL scheme messes up the port checking below.
                 $normalized_base_url = str_replace(array('https://', 'http://'), '', $options['base_url']);
             }
             // Ask for an absolute URL with our modified base URL.
             $options['absolute'] = TRUE;
             $options['base_url'] = $url_scheme . '://' . $config['domains'][$options['language']->getId()];
             // In case either the original base URL or the HTTP host contains a
             // port, retain it.
             if (isset($normalized_base_url) && strpos($normalized_base_url, ':') !== FALSE) {
                 list(, $port) = explode(':', $normalized_base_url);
                 $options['base_url'] .= ':' . $port;
             } elseif ($url_scheme == 'http' && $port != 80 || $url_scheme == 'https' && $port != 443) {
                 $options['base_url'] .= ':' . $port;
             }
             if (isset($options['https'])) {
                 if ($options['https'] === TRUE) {
                     $options['base_url'] = str_replace('http://', 'https://', $options['base_url']);
                 } elseif ($options['https'] === FALSE) {
                     $options['base_url'] = str_replace('https://', 'http://', $options['base_url']);
                 }
             }
             // Add Drupal's subfolder from the base_path if there is one.
             $options['base_url'] .= rtrim(base_path(), '/');
             if ($bubbleable_metadata) {
                 $bubbleable_metadata->addCacheContexts(['languages:' . LanguageInterface::TYPE_URL, 'url.site']);
             }
         }
     }
     return $path;
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:62,代码来源:LanguageNegotiationUrl.php

示例3: processOutbound

 /**
  * {@inheritdoc}
  */
 public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL)
 {
     // If appropriate, process outbound to add a query parameter to the url and
     // remove the language option, so that url negotiator does not rewrite the
     // url.
     // First, check if processing conditions are met.
     if (!($request && !empty($options['route']) && $this->hasLowerLanguageNegotiationWeight() && $this->meetsContentEntityRoutesCondition($options['route'], $request))) {
         return $path;
     }
     if (isset($options['language']) || ($langcode = $this->getLangcode($request))) {
         // If the language option is set, unset it, so that the url language
         // negotiator does not rewrite the url.
         if (isset($options['language'])) {
             $langcode = $options['language']->getId();
             unset($options['language']);
         }
         if (isset($options['query']) && is_string($options['query'])) {
             $query = [];
             parse_str($options['query'], $query);
             $options['query'] = $query;
         } else {
             $options['query'] = [];
         }
         if (!isset($options['query'][static::QUERY_PARAMETER])) {
             $query_addon = [static::QUERY_PARAMETER => $langcode];
             $options['query'] += $query_addon;
             // @todo Remove this once https://www.drupal.org/node/2507005 lands.
             $path .= (strpos($path, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($query_addon);
         }
         if ($bubbleable_metadata) {
             // Cached URLs that have been processed by this outbound path
             // processor must be:
             $bubbleable_metadata->addCacheContexts(['url.query_args:' . static::QUERY_PARAMETER]);
         }
     }
     return $path;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:40,代码来源:LanguageNegotiationContentEntity.php


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