You are here

public function EntityReferenceFieldItemList::defaultValuesFormSubmit in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php \Drupal\Core\Field\EntityReferenceFieldItemList::defaultValuesFormSubmit()

Processes the submitted default value.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure instance-level default value.

Parameters

array $element: The default value form element.

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Return value

array The field default value.

Overrides FieldItemList::defaultValuesFormSubmit

File

core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php, line 111
Contains \Drupal\Core\Field\EntityReferenceFieldItemList.

Class

EntityReferenceFieldItemList
Defines a item list class for entity reference fields.

Namespace

Drupal\Core\Field

Code

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 = array();
  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::entityManager()
    ->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;
}