You are here

public static function DynamicEntityReferenceItem::fieldSettingsFormValidate in Dynamic Entity Reference 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php \Drupal\dynamic_entity_reference\Plugin\Field\FieldType\DynamicEntityReferenceItem::fieldSettingsFormValidate()

Form element validation handler; Stores the new values in the form state.

Parameters

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.

Overrides EntityReferenceItem::fieldSettingsFormValidate

File

src/Plugin/Field/FieldType/DynamicEntityReferenceItem.php, line 369

Class

DynamicEntityReferenceItem
Defines the 'dynamic_entity_reference' entity field type.

Namespace

Drupal\dynamic_entity_reference\Plugin\Field\FieldType

Code

public static function fieldSettingsFormValidate(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\field\Entity\FieldConfig $field */
  $field = $form_state
    ->getFormObject()
    ->getEntity();
  foreach (static::getTargetTypes($field
    ->getSettings()) as $target_type) {

    // If no checkboxes were checked for 'target_bundles', store NULL ("all
    // bundles are referenceable") rather than empty array ("no bundle is
    // referenceable" - typically happens when all referenceable bundles have
    // been deleted).
    if ($form_state
      ->getValue([
      'settings',
      $target_type,
      'handler_settings',
      'target_bundles',
    ]) === []) {
      $form_state
        ->setValue([
        'settings',
        $target_type,
        'handler_settings',
        'target_bundles',
      ], NULL);
    }

    // Don't store the 'target_bundles_update' button value into the field
    // config settings.
    $form_state
      ->unsetValue([
      'settings',
      $target_type,
      'handler_settings',
      'target_bundles_update',
    ]);
    $form_state
      ->unsetValue([
      'settings',
      $target_type,
      'handler_submit',
    ]);
  }
}