public static function ImageCropWidget::processCropTypesRequired in Image Widget Crop 8.2
Render API callback: retrieve options for current form element.
Parameters
array $element: An associative array containing the properties and children of the form actions container.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $complete_form: The complete form structure.
Return value
array The processed element.
File
- src/
Plugin/ Field/ FieldWidget/ ImageCropWidget.php, line 265
Class
- ImageCropWidget
- Plugin implementation of the 'image_widget_crop' widget.
Namespace
Drupal\image_widget_crop\Plugin\Field\FieldWidgetCode
public static function processCropTypesRequired(array &$element, FormStateInterface $form_state, array &$complete_form) {
if (!$form_state
->getTriggeringElement()) {
return $element;
}
// Only display options chosen on 'crop_list',
// element in current form element.
$crop_list_form_element = self::getImageCropWidgetElement($form_state, 'crop_list');
if (empty($crop_list_form_element)) {
return $element;
}
$crop_list_options = $crop_list_form_element['#options'];
$crop_list_default_value = array_flip($crop_list_form_element['#default_value']);
// Populate element options with crop_list selected options.
$element['#options'] = array_intersect_key($crop_list_options, $crop_list_default_value);
return $element;
}