function ImageItem::validateDefaultImageForm
Same name in other branches
- 9 core/modules/image/src/Plugin/Field/FieldType/ImageItem.php \Drupal\image\Plugin\Field\FieldType\ImageItem::validateDefaultImageForm()
- 8.9.x core/modules/image/src/Plugin/Field/FieldType/ImageItem.php \Drupal\image\Plugin\Field\FieldType\ImageItem::validateDefaultImageForm()
- 11.x core/modules/image/src/Plugin/Field/FieldType/ImageItem.php \Drupal\image\Plugin\Field\FieldType\ImageItem::validateDefaultImageForm()
Validates the managed_file element for the default Image form.
This function ensures the fid is a scalar value and not an array. It is assigned as an #element_validate callback in \Drupal\image\Plugin\Field\FieldType\ImageItem::defaultImageForm().
Parameters
array $element: The form element to process.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
File
-
core/
modules/ image/ src/ Plugin/ Field/ FieldType/ ImageItem.php, line 504
Class
- ImageItem
- Plugin implementation of the 'image' field type.
Namespace
Drupal\image\Plugin\Field\FieldTypeCode
public static function validateDefaultImageForm(array &$element, FormStateInterface $form_state) {
// Consolidate the array value of this field to a single FID as #extended
// for default image is not TRUE and this is a single value.
if (isset($element['fids']['#value'][0])) {
$value = $element['fids']['#value'][0];
// Convert the file ID to a uuid.
if ($file = \Drupal::entityTypeManager()->getStorage('file')
->load($value)) {
$value = $file->uuid();
}
}
else {
$value = '';
}
$form_state->setValueForElement($element, $value);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.