function EntityReferenceFieldItemList::defaultValuesFormSubmit
Same name in other branches
- 9 core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php \Drupal\Core\Field\EntityReferenceFieldItemList::defaultValuesFormSubmit()
- 10 core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php \Drupal\Core\Field\EntityReferenceFieldItemList::defaultValuesFormSubmit()
- 11.x core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php \Drupal\Core\Field\EntityReferenceFieldItemList::defaultValuesFormSubmit()
Overrides FieldItemList::defaultValuesFormSubmit
File
-
core/
lib/ Drupal/ Core/ Field/ EntityReferenceFieldItemList.php, line 106
Class
- EntityReferenceFieldItemList
- Defines a item list class for entity reference fields.
Namespace
Drupal\Core\FieldCode
public function defaultValuesFormSubmit(array $element, array &$form, FormStateInterface $form_state) {
$default_value = parent::defaultValuesFormSubmit($element, $form, $form_state);
// Convert numeric IDs to UUIDs to ensure config deployability.
$ids = [];
foreach ($default_value as $delta => $properties) {
if (isset($properties['entity']) && $properties['entity']->isNew()) {
// This may be a newly created term.
$properties['entity']->save();
$default_value[$delta]['target_id'] = $properties['entity']->id();
unset($default_value[$delta]['entity']);
}
$ids[] = $default_value[$delta]['target_id'];
}
$entities = \Drupal::entityTypeManager()->getStorage($this->getSetting('target_type'))
->loadMultiple($ids);
foreach ($default_value as $delta => $properties) {
unset($default_value[$delta]['target_id']);
$default_value[$delta]['target_uuid'] = $entities[$properties['target_id']]->uuid();
}
return $default_value;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.