FieldStorageAddForm::fieldNameExists

public FieldStorageAddForm::fieldNameExists($value, $element, FormStateInterface $form_state)

Checks if a field machine name is taken.

Parameters

string $value: The machine name, not prefixed.

array $element: An array containing the structure of the 'field_name' element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

bool Whether or not the field machine name is taken.

File

core/modules/field_ui/src/Form/FieldStorageAddForm.php, line 542

Class

FieldStorageAddForm
Provides a form for the "field storage" add page.

Namespace

Drupal\field_ui\Form

Code

public function fieldNameExists($value, $element, FormStateInterface $form_state) {
  // Don't validate the case when an existing field has been selected.
  if ($form_state->getValue('existing_storage_name')) {
    return FALSE;
  }

  // Add the field prefix.
  $field_name = $this->configFactory->get('field_ui.settings')->get('field_prefix') . $value;

  $field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->entityTypeId);
  return isset($field_storage_definitions[$field_name]);
}
doc_Drupal
2016-10-29 09:12:07
Comments
Leave a Comment

Please login to continue.