protected function FieldOverview::validateAddExisting

Validates the 're-use existing field' row.

Parameters

array $form: An associative array containing the structure of the form.

array $form_state: A reference to a keyed array containing the current state of the form.

See also

Drupal\field_ui\FieldOverview::validate()

1 call to FieldOverview::validateAddExisting()
FieldOverview::validate in drupal/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
Overrides Drupal\field_ui\OverviewBase::validate().

File

drupal/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php, line 500
Definition of Drupal\field_ui\FieldOverview.

Class

FieldOverview
Field UI field overview form.

Namespace

Drupal\field_ui

Code

protected function validateAddExisting(array $form, array &$form_state) {

  // The form element might be absent if no existing fields can be added to
  // this bundle.
  if (isset($form_state['values']['fields']['_add_existing_field'])) {
    $field = $form_state['values']['fields']['_add_existing_field'];

    // Validate if any information was provided in the
    // 're-use existing field' row.
    if (array_filter(array(
      $field['label'],
      $field['field_name'],
      $field['widget_type'],
    ))) {

      // Missing label.
      if (!$field['label']) {
        form_set_error('fields][_add_existing_field][label', t('Re-use existing field: you need to provide a label.'));
      }

      // Missing existing field name.
      if (!$field['field_name']) {
        form_set_error('fields][_add_existing_field][field_name', t('Re-use existing field: you need to select a field.'));
      }

      // Missing widget type.
      if (!$field['widget_type']) {
        form_set_error('fields][_add_existing_field][widget_type', t('Re-use existing field: you need to select a widget.'));
      }
      elseif ($field['field_name'] && ($existing_field = field_info_field($field['field_name']))) {
        $widget_types = field_ui_widget_type_options($existing_field['type']);
        if (!isset($widget_types[$field['widget_type']])) {
          form_set_error('fields][_add_existing_field][widget_type', t('Re-use existing field: invalid widget.'));
        }
      }
    }
  }
}