public static function WebformImageSelectImages::getElementImages in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_image_select/src/Entity/WebformImageSelectImages.php \Drupal\webform_image_select\Entity\WebformImageSelectImages::getElementImages()
Get webform image select element images.
Parameters
array $element: A webform image select element.
Return value
array An associative array of images.
Overrides WebformImageSelectImagesInterface::getElementImages
3 calls to WebformImageSelectImages::getElementImages()
- WebformImageSelect::initialize in modules/
webform_image_select/ src/ Plugin/ WebformElement/ WebformImageSelect.php - Initialize an element to be displayed, rendered, or exported.
- WebformImageSelectImagesListBuilder::buildImages in modules/
webform_image_select/ src/ WebformImageSelectImagesListBuilder.php - Build images for a webform image select images entity.
- WebformImageSelectImagesTest::testWebformImageSelectImages in modules/
webform_image_select/ tests/ src/ Functional/ WebformImageSelectImagesTest.php - Tests webform image select images entity.
File
- modules/
webform_image_select/ src/ Entity/ WebformImageSelectImages.php, line 155
Class
- WebformImageSelectImages
- Defines the webform image select images entity.
Namespace
Drupal\webform_image_select\EntityCode
public static function getElementImages(array &$element) {
// If element already has #images return them.
if (isset($element['#images']) && is_array($element['#images'])) {
return $element['#images'];
}
// Return empty image if element does not define an images id.
if (empty($element['#images']) || !is_string($element['#images'])) {
return [];
}
// If images have been set return them.
// This allows dynamic images to be overridden.
$id = $element['#images'];
if ($webform_images = WebformImageSelectImages::load($id)) {
$images = $webform_images
->getImages() ?: [];
}
else {
$images = [];
}
// Alter images using hook_webform_image_select_images_alter()
// and/or hook_webform_image_select_images_WEBFORM_IMAGE_SELECT_IMAGES_ID_alter() hook.
// @see webform.api.php
\Drupal::moduleHandler()
->alter('webform_image_select_images_' . $id, $images, $element);
\Drupal::moduleHandler()
->alter('webform_image_select_images', $images, $element, $id);
// Log empty images.
if (empty($images)) {
\Drupal::logger('webform_image_select')
->notice('Images %id do not exist.', [
'%id' => $id,
]);
}
return $images;
}