function FieldStorageAddForm::getExistingFieldStorageOptions

Returns an array of existing field storages that can be added to a bundle.

Return value

array An array of existing field storages keyed by name.

1 call to FieldStorageAddForm::getExistingFieldStorageOptions()
FieldStorageAddForm::buildForm in core/modules/field_ui/src/Form/FieldStorageAddForm.php
Form constructor.

File

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

Class

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

Namespace

Drupal\field_ui\Form

Code

protected function getExistingFieldStorageOptions() {
  $options = [];
  // Load the field_storages and build the list of options.
  $field_types = $this->fieldTypePluginManager
    ->getDefinitions();
  foreach ($this->entityFieldManager
    ->getFieldStorageDefinitions($this->entityTypeId) as $field_name => $field_storage) {
    // Do not show:
    // - non-configurable field storages,
    // - locked field storages,
    // - field storages that should not be added via user interface,
    // - field storages that already have a field in the bundle.
    $field_type = $field_storage->getType();
    if ($field_storage instanceof FieldStorageConfigInterface && !$field_storage->isLocked() && empty($field_types[$field_type]['no_ui']) && !in_array($this->bundle, $field_storage->getBundles(), TRUE)) {
      $options[$field_name] = $this->t('@type: @field', [
        '@type' => $field_types[$field_type]['label'],
        '@field' => $field_name,
      ]);
    }
  }
  asort($options);
  return $options;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.