You are here

public function FieldStorageAddForm::fieldNameExists in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/field_ui/src/Form/FieldStorageAddForm.php \Drupal\field_ui\Form\FieldStorageAddForm::fieldNameExists()
  2. 9 core/modules/field_ui/src/Form/FieldStorageAddForm.php \Drupal\field_ui\Form\FieldStorageAddForm::fieldNameExists()

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 574

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->entityFieldManager
    ->getFieldStorageDefinitions($this->entityTypeId);
  return isset($field_storage_definitions[$field_name]);
}