Problem/Motivation
When I choose a style option of the plugin type "property", the template variable includes the index of my chosen option instead of the value of that option.
Instead, I expect the template variable to be set to the value of the chosen option.
Steps to reproduce
Configure style options:
options:
hide_title:
plugin: property
label: Hide title
options:
- label: 'No - always show the title'
- label: 'Yes - show the title for screen readers only'
value: true
contexts:
paragraphs:
card_grid:
options:
hide_title: true
Create a page with a paragraph with a type with this style option and set it to 'Yes'.
The result is my template has a variable
$variables['elements']['#hide_title'] = 1
I expect instead for the template variable to have the value true
Proposed resolution
Property::build() has:
$value = $this->getValue('property') ?? NULL;
$option_definition = $this->getConfiguration('options');
if (is_array($value)) {
$property = implode(' ',
array_map(function ($index) use ($option_definition) {
return $option_definition[$index]['value'] ?? NULL;
}, $value)
);
}
else {
$property = $value ?? NULL;
}
Since there is no example for the property plugin (
π¬
Add property plugin example usage
Active
), it isn't clear when we should expect $value
to be an array. In my example, $value
is set to the index of my chosen option.
In order for the template variable to contain the value of my option, the else
statement should be:
else {
$property = $option_definition[$value]['value'] ?? NULL;
}
Is this a bug, or is there another structure I should use in my definition?
Remaining tasks
User interface changes
API changes
Data model changes