0

I am writing a Views style plugin, and I have a text field (input) that I want to be able to accept Contextual Filter arguments (or potentially field values). I am envisioning it working the same as the input that shows up when you click "Override title" under the "WHEN THE FILTER VALUE IS AVAILABLE OR A DEFAULT IS PROVIDED" fieldset. So, for example, you could add {{ arguments.nid }} into the text field.

This (below) is my current form element/text field that I'd want to be able to accept the arguments. I looked into the Views codebase, but was wasn't able to figure out how Views implements accepting arguments in a text field.

$form['display']['title'] = [
    '#title' => t('Chart title'),
    '#type' => 'textfield',
    '#default_value' => $options['title'],
    '#parents' => array_merge($parents, ['title']),
  ];

Any help would be greatly appreciated!

1 Answer 1

1

To replace argument tokens in a Views plugin you need:

$tokens = $this->view->build_info['substitutions'];
$value = $this->viewsTokenReplace($value, $tokens);

If you've based your plugin on StylePluginBase you can use StylePluginBase::tokenizeValue, which additionally replaces row tokens as well.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.