diff --git a/core/modules/views/src/Plugin/views/area/TokenizeAreaPluginBase.php b/core/modules/views/src/Plugin/views/area/TokenizeAreaPluginBase.php index 96c5b5c..d29fa1a 100644 --- a/core/modules/views/src/Plugin/views/area/TokenizeAreaPluginBase.php +++ b/core/modules/views/src/Plugin/views/area/TokenizeAreaPluginBase.php @@ -111,44 +111,3 @@ public function tokenizeValue($value) { // As we add the globalTokenForm() we also should replace the token here. return $this->globalTokenReplace($value); } - - /** - * Indicates whether the value has a special Views token. - * - * @param string $value - * The string to check - * - * @return bool - * TRUE if the string has a Views token. - */ - public function hasViewsToken($value) { - return $this->view->getStyle()->hasViewsToken($value); - } - - /** - * Indicates whether the value has a global token. - * - * @param string $value - * The string to check - * - * @return bool - * TRUE if the string has a global token. - */ - public function hasGlobalToken($value) { - return $this->view->getStyle()->hasGlobalToken($value); - } - - /** - * Indicates whether the value has a special Views token or a global token. - * - * @param string $value - * The string to check - * - * @return bool - * TRUE if the string has a Global token. - */ - public function hasToken($value) { - return $this->view->getStyle()->hasToken($value); - } - -} diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index 4459ac2..fab7664 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -337,7 +337,7 @@ public function elementClasses($row_index = NULL) { * tokens so they will all be available. */ public function tokenizeValue($value, $row_index = NULL) { - if (strpos($value, '[') !== FALSE || strpos($value, '!') !== FALSE || strpos($value, '%') !== FALSE) { + if ($this->view->getStyle()->hasRowToken($value) || $this->view->getStyle()->hasArgToken($value)) { $fake_item = array( 'alter_text' => TRUE, 'text' => $value, diff --git a/core/modules/views/src/Plugin/views/style/StylePluginBase.php b/core/modules/views/src/Plugin/views/style/StylePluginBase.php index 7ddcecb..5bfc0d1 100644 --- a/core/modules/views/src/Plugin/views/style/StylePluginBase.php +++ b/core/modules/views/src/Plugin/views/style/StylePluginBase.php @@ -214,7 +214,7 @@ public function getRowClass($row_index) { * Take a value and apply token replacement logic to it. */ public function tokenizeValue($value, $row_index) { - if ($this->hasGlobalToken($value) || $this->hasViewsToken($value)) { + if ($this->hasArgToken($value) || $this->hasRowToken($value)) { // Row tokens might be empty, for example for node row style. $tokens = isset($this->rowTokens[$row_index]) ? $this->rowTokens[$row_index] : array(); if (!empty($this->view->build_info['substitutions'])) { @@ -230,7 +230,7 @@ public function tokenizeValue($value, $row_index) { } /** - * Indicates whether the value has a special Views token. + * Indicates whether the value has a Views argument token. * * @param string $value * The string to check @@ -238,7 +238,7 @@ public function tokenizeValue($value, $row_index) { * @return bool * TRUE if the string has a Views token. */ - public function hasViewsToken($value) { + public function hasArgToken($value) { // If the string definitely does not contain a token, return FALSE // immediately for performance. if ((strpos($value, '!') === FALSE) && (strpos($value, '%') === FALSE)) { @@ -249,6 +249,27 @@ public function hasViewsToken($value) { } /** + * Indicates whether the value has a Views row-level token. + * + * @param string $value + * The string to check + * + * @return bool + * TRUE if the string has a global token. + */ + public function hasRowToken($value) { + // If the string definitely does not contain a token, return FALSE + // immediately for performance. + if (strpos($value, '[') === FALSE) { + return FALSE; + } + // Otherwise, scan for valid token patterns. + $tokens = \Drupal::token()->scan($value); + // Match any non-empty string between [ and ] that does not contain [ or ]. + return (preg_match('/\[[^\[\]]+\]/', $value) !== FALSE); + } + + /** * Indicates whether the value has a global token. * * @param string $value @@ -256,6 +277,8 @@ public function hasViewsToken($value) { * * @return bool * TRUE if the string has a global token. + * + * @see \Drupal\Core\Utility\Token */ public function hasGlobalToken($value) { // If the string definitely does not contain a token, return FALSE @@ -264,7 +287,8 @@ public function hasGlobalToken($value) { return FALSE; } // Otherwise, scan for valid token patterns. - return !empty(\Drupal::token()->scan($value)); + $tokens = \Drupal::token()->scan($value); + return (!empty($tokens)); } /** @@ -274,10 +298,10 @@ public function hasGlobalToken($value) { * The string to check * * @return bool - * TRUE if the string has a Global token. + * TRUE if the string has any token. */ public function hasToken($value) { - return ($this->hasViewsToken($value) || $this->hasGlobalToken($value)); + return ($this->hasArgToken($value) || $this->hasRowToken($value) || $this->hasGlobalToken($value)); } /**