You are here

public static function ImageCropWidget::process in Image Widget Crop 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/ImageCropWidget.php \Drupal\image_widget_crop\Plugin\Field\FieldWidget\ImageCropWidget::process()

Form API callback: Processes a crop_image field element.

Expands the image_image type to include the alt and title fields.

This method is assigned as a #process callback in formElement() method.

Return value

array The elements with parents fields.

Overrides ImageWidget::process

File

src/Plugin/Field/FieldWidget/ImageCropWidget.php, line 118

Class

ImageCropWidget
Plugin implementation of the 'image_widget_crop' widget.

Namespace

Drupal\image_widget_crop\Plugin\Field\FieldWidget

Code

public static function process($element, FormStateInterface $form_state, $form) {
  if ($element['#files']) {
    foreach ($element['#files'] as $file) {
      $element['image_crop'] = [
        '#type' => 'image_crop',
        '#file' => $file,
        '#crop_type_list' => $element['#crop_list'],
        '#crop_preview_image_style' => $element['#crop_preview_image_style'],
        '#show_default_crop' => $element['#show_default_crop'],
        '#show_crop_area' => $element['#show_crop_area'],
        '#warn_multiple_usages' => $element['#warn_multiple_usages'],
      ];
    }
  }
  return parent::process($element, $form_state, $form);
}