public static function SvgImageFieldWidget::validateRequiredFields in SVG Image Field 8
Same name and namespace in other branches
- 2.1.x src/Plugin/Field/FieldWidget/SvgImageFieldWidget.php \Drupal\svg_image_field\Plugin\Field\FieldWidget\SvgImageFieldWidget::validateRequiredFields()
- 2.0.x src/Plugin/Field/FieldWidget/SvgImageFieldWidget.php \Drupal\svg_image_field\Plugin\Field\FieldWidget\SvgImageFieldWidget::validateRequiredFields()
Validate callback for alt and title field, if the user wants them required.
This is separated in a validate function instead of a #required flag to avoid being validated on the process callback.
File
- src/
Plugin/ Field/ FieldWidget/ SvgImageFieldWidget.php, line 268
Class
- SvgImageFieldWidget
- Plugin implementation of the 'image_image' widget.
Namespace
Drupal\svg_image_field\Plugin\Field\FieldWidgetCode
public static function validateRequiredFields($element, FormStateInterface $form_state) {
// Only do validation if the function is triggered from other places than
// the image process form.
if (!in_array('file_managed_file_submit', $form_state
->getTriggeringElement()['#submit'])) {
// If the image is not there, we do not check for empty values.
$parents = $element['#parents'];
$field = array_pop($parents);
$image_field = NestedArray::getValue($form_state
->getUserInput(), $parents);
// We check for the array key, so that it can be NULL (like if the user
// submits the form without using the "upload" button).
if (!array_key_exists($field, $image_field)) {
return;
}
}
else {
$form_state
->setLimitValidationErrors([]);
}
}