本文整理汇总了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);
}
示例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;
}