function ImageWidget::validateRequiredFields

Same name in other branches
  1. 8.9.x core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php \Drupal\image\Plugin\Field\FieldWidget\ImageWidget::validateRequiredFields()
  2. 10 core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php \Drupal\image\Plugin\Field\FieldWidget\ImageWidget::validateRequiredFields()
  3. 11.x core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php \Drupal\image\Plugin\Field\FieldWidget\ImageWidget::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

core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php, line 292

Class

ImageWidget
Plugin implementation of the 'image_image' widget.

Namespace

Drupal\image\Plugin\Field\FieldWidget

Code

public static function validateRequiredFields($element, FormStateInterface $form_state) {
    // Only do validation if the function is triggered from other places than
    // the image process form.
    $triggering_element = $form_state->getTriggeringElement();
    if (!empty($triggering_element['#submit']) && in_array('file_managed_file_submit', $triggering_element['#submit'], TRUE)) {
        $form_state->setLimitValidationErrors([]);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.