EntityReferenceFieldItemList::defaultValuesFormSubmit

public EntityReferenceFieldItemList::defaultValuesFormSubmit(array $element, array &$form, FormStateInterface $form_state)

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 106

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;
}
doc_Drupal
2016-10-29 09:07:21
Comments
Leave a Comment

Please login to continue.