public static function WebformImageSelect::setOptions in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_image_select/src/Element/WebformImageSelect.php \Drupal\webform_image_select\Element\WebformImageSelect::setOptions()
Set element #options from #images.
Parameters
array $element: A Webform image select element.
2 calls to WebformImageSelect::setOptions()
- WebformImageSelect::initialize in modules/
webform_image_select/ src/ Plugin/ WebformElement/ WebformImageSelect.php - Initialize an element to be displayed, rendered, or exported.
- WebformImageSelect::processSelect in modules/
webform_image_select/ src/ Element/ WebformImageSelect.php - Processes a select list form element.
File
- modules/
webform_image_select/ src/ Element/ WebformImageSelect.php, line 130
Class
- WebformImageSelect
- Provides a webform element for a selecting an image.
Namespace
Drupal\webform_image_select\ElementCode
public static function setOptions(array &$element) {
// Randomize images.
if (!empty($element['#images_randomize'])) {
$element['#images'] = WebformElementHelper::randomize($element['#images']);
}
// Convert #images to #options and make sure images are keyed by value.
if (empty($element['#options'])) {
$options = [];
foreach ($element['#images'] as $value => &$image) {
if (isset($image['text'])) {
// Apply XSS filter to image text.
$image['text'] = WebformHtmlEditor::stripTags($image['text']);
// Strip all HTML tags from the option.
$options[$value] = strip_tags($image['text']);
}
else {
$options[$value] = $value;
}
}
$element['#options'] = $options;
}
}