public function TokenArgument::tokenScan in Views Token Argument 8
Same name and namespace in other branches
- 2.0.x src/Plugin/views/argument_default/TokenArgument.php \Drupal\views_argument_token\Plugin\views\argument_default\TokenArgument::tokenScan()
Scans a string to detect potential tokens.
Parameters
string $text: The string to scan.
Return value
string[] An array containing potential tokens ready for processing.
2 calls to TokenArgument::tokenScan()
- TokenArgument::getArgument in src/
Plugin/ views/ argument_default/ TokenArgument.php - Return the default argument.
- TokenArgument::processToken in src/
Plugin/ views/ argument_default/ TokenArgument.php - Process tokens as raw values.
File
- src/
Plugin/ views/ argument_default/ TokenArgument.php, line 215
Class
- TokenArgument
- The Token argument default handler.
Namespace
Drupal\views_argument_token\Plugin\views\argument_defaultCode
public function tokenScan($text) {
// Matches tokens with the following pattern: [$type:$name]
// $type and $name may not contain [ ] characters.
// $type may not contain : or whitespace characters, but $name may.
preg_match_all('/
\\[ # [ - pattern start
([^\\s\\[\\]:]*) # match $type not containing whitespace : [ or ]
: # : - separator
([^\\[\\]]*) # match $name not containing [ or ]
\\] # ] - pattern end
/x', $text, $matches);
$types = $matches[1];
$tokens = $matches[2];
// Iterate through the matches, building an associative array containing
// $tokens grouped by $types, pointing to the version of the token found in
// the source text. For example, $results['node']['title'] = '[node:title]'.
$results = array();
for ($i = 0; $i < count($tokens); $i++) {
$results[$types[$i]][$tokens[$i]] = $matches[0][$i];
}
return $results;
}