protected function ViewfieldFormatterDefault::processArguments in Viewfield 8.3
Perform argument parsing and token replacement.
Parameters
string $argument_string: The raw argument string.
\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity containing this field.
Return value
array The array of processed arguments.
1 call to ViewfieldFormatterDefault::processArguments()
- ViewfieldFormatterDefault::viewElements in src/
Plugin/ Field/ FieldFormatter/ ViewfieldFormatterDefault.php - Builds a renderable array for a field value.
File
- src/
Plugin/ Field/ FieldFormatter/ ViewfieldFormatterDefault.php, line 217
Class
- ViewfieldFormatterDefault
- Viewfield Default Formatter plugin definition.
Namespace
Drupal\viewfield\Plugin\Field\FieldFormatterCode
protected function processArguments($argument_string, FieldableEntityInterface $entity) {
$arguments = [];
if (!empty($argument_string)) {
$pos = 0;
while ($pos < strlen($argument_string)) {
$found = FALSE;
// If string starts with a quote, start after quote and get everything
// before next quote.
if (strpos($argument_string, '"', $pos) === $pos) {
if (($quote = strpos($argument_string, '"', ++$pos)) !== FALSE) {
// Skip pairs of quotes.
while (!(($ql = strspn($argument_string, '"', $quote)) & 1)) {
$quote = strpos($argument_string, '"', $quote + $ql);
}
$arguments[] = str_replace('""', '"', substr($argument_string, $pos, $quote + $ql - $pos - 1));
$pos = $quote + $ql + 1;
$found = TRUE;
}
}
else {
$arguments = explode('/', $argument_string);
$pos = strlen($argument_string) + 1;
$found = TRUE;
}
if (!$found) {
$arguments[] = substr($argument_string, $pos);
$pos = strlen($argument_string);
}
}
$token_service = \Drupal::token();
$token_data = [
$entity
->getEntityTypeId() => $entity,
];
foreach ($arguments as $key => $value) {
$arguments[$key] = $token_service
->replace($value, $token_data);
}
}
return $arguments;
}