class WebformImageSelectImages in Webform 8.5
Same name in this branch
- 8.5 modules/webform_image_select/src/Element/WebformImageSelectImages.php \Drupal\webform_image_select\Element\WebformImageSelectImages
- 8.5 modules/webform_image_select/src/Entity/WebformImageSelectImages.php \Drupal\webform_image_select\Entity\WebformImageSelectImages
Same name and namespace in other branches
- 6.x modules/webform_image_select/src/Element/WebformImageSelectImages.php \Drupal\webform_image_select\Element\WebformImageSelectImages
Provides a form element to assist in creation of webform select image images.
Plugin annotation
@FormElement("webform_image_select_images");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\webform_image_select\Element\WebformImageSelectImages
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of WebformImageSelectImages
2 #type uses of WebformImageSelectImages
- WebformImageSelectElementImages::processWebformImageSelectElementImages in modules/
webform_image_select/ src/ Element/ WebformImageSelectElementImages.php - Processes a webform element image select images element.
- WebformImageSelectImagesForm::form in modules/
webform_image_select/ src/ WebformImageSelectImagesForm.php - Gets the actual form array to be built.
File
- modules/
webform_image_select/ src/ Element/ WebformImageSelectImages.php, line 16
Namespace
Drupal\webform_image_select\ElementView source
class WebformImageSelectImages extends FormElement {
/**
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
return [
'#input' => TRUE,
'#label' => t('image'),
'#labels' => t('images'),
'#min_items' => 3,
'#empty_items' => 1,
'#add_more_items' => 1,
'#process' => [
[
$class,
'processWebformImageSelectImages',
],
],
'#theme_wrappers' => [
'form_element',
],
];
}
/**
* {@inheritdoc}
*/
public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
if ($input === FALSE) {
if (!isset($element['#default_value'])) {
return [];
}
return $element['#default_value'];
}
elseif (is_array($input) && isset($input['images'])) {
return $input['images'];
}
else {
return NULL;
}
}
/**
* Process images and build images widget.
*/
public static function processWebformImageSelectImages(&$element, FormStateInterface $form_state, &$complete_form) {
$element['#tree'] = TRUE;
// Add validate callback that extracts the associative array of images.
$element['#element_validate'] = [
[
get_called_class(),
'validateWebformImageSelectImages',
],
];
// Wrap this $element in a <div> that handle #states.
WebformElementHelper::fixStatesWrapper($element);
$properties = [
'#label',
'#labels',
'#min_items',
'#empty_items',
'#add_more_items',
];
$element['images'] = array_intersect_key($element, array_combine($properties, $properties)) + [
'#type' => 'webform_multiple',
'#key' => 'value',
'#header' => [
[
'data' => t('Image value'),
'width' => '25%',
],
[
'data' => t('Image text'),
'width' => '25%',
],
[
'data' => t('Image src'),
'width' => '50%',
],
],
'#element' => [
'value' => [
'#type' => 'textfield',
'#title' => t('Image value'),
'#title_display' => 'invisible',
'#placeholder' => t('Enter value…'),
'#error_no_message' => TRUE,
'#attributes' => [
'class' => [
'js-webform-options-sync',
],
],
],
'text' => [
'#type' => 'textfield',
'#title' => t('Image text'),
'#title_display' => 'invisible',
'#placeholder' => t('Enter text…'),
'#error_no_message' => TRUE,
],
'src' => [
'#type' => 'textfield',
'#title' => t('Image src'),
'#title_display' => 'invisible',
'#placeholder' => t('Enter image src…'),
'#error_no_message' => TRUE,
],
],
'#error_no_message' => TRUE,
'#add_more_input_label' => t('more images'),
'#default_value' => isset($element['#default_value']) ? $element['#default_value'] : [],
];
if (function_exists('imce_process_url_element')) {
$src_element =& $element['images']['#element']['src'];
imce_process_url_element($src_element, 'link');
$element['#attached']['library'][] = 'webform/imce.input';
}
elseif (\Drupal::currentUser()
->hasPermission('administer modules')) {
$element['imce_message'] = [
'#type' => 'webform_message',
'#message_type' => 'warning',
'#message_message' => t('Install the <a href=":href">IMCE module</a> to manage and uploaded image files.', [
':href' => 'https://www.drupal.org/project/imce',
]),
'#message_close' => TRUE,
'#message_id' => 'webform_imce_message',
'#message_storage' => WebformMessage::STORAGE_LOCAL,
];
}
$element['#attached']['library'][] = 'webform/webform.element.options.admin';
return $element;
}
/**
* Validates webform image select images element.
*/
public static function validateWebformImageSelectImages(&$element, FormStateInterface $form_state, &$complete_form) {
$options = NestedArray::getValue($form_state
->getValues(), $element['images']['#parents']);
// Validate required images.
if (!empty($element['#required']) && empty($options)) {
WebformElementHelper::setRequiredError($element, $form_state);
return;
}
$form_state
->setValueForElement($element, $options);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormElement:: |
public static | function | Adds autocomplete functionality to elements. | |
FormElement:: |
public static | function | #process callback for #pattern form element property. | |
FormElement:: |
public static | function | #element_validate callback for #pattern form element property. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
RenderElement:: |
public static | function | Adds Ajax information about an element to communicate with JavaScript. | |
RenderElement:: |
public static | function | Adds members of this group as actual elements for rendering. | |
RenderElement:: |
public static | function | Form element processing handler for the #ajax form property. | 1 |
RenderElement:: |
public static | function | Arranges elements into groups. | |
RenderElement:: |
public static | function |
Sets a form element's class attribute. Overrides ElementInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
WebformImageSelectImages:: |
public | function |
Returns the element properties for this element. Overrides ElementInterface:: |
|
WebformImageSelectImages:: |
public static | function | Process images and build images widget. | |
WebformImageSelectImages:: |
public static | function | Validates webform image select images element. | |
WebformImageSelectImages:: |
public static | function |
Determines how user input is mapped to an element's #value property. Overrides FormElement:: |