function FieldStorageReuseForm::getExistingFieldStorageOptions

Same name and namespace in other branches
  1. 10 core/modules/field_ui/src/Form/FieldStorageReuseForm.php \Drupal\field_ui\Form\FieldStorageReuseForm::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 FieldStorageReuseForm::getExistingFieldStorageOptions()
FieldStorageReuseForm::buildForm in core/modules/field_ui/src/Form/FieldStorageReuseForm.php
Form constructor.

File

core/modules/field_ui/src/Form/FieldStorageReuseForm.php, line 204

Class

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

Namespace

Drupal\field_ui\Form

Code

protected function getExistingFieldStorageOptions() : array {
    $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] = [
                'field_type' => $field_types[$field_type]['label'],
                'field_name' => $field_name,
                'field_storage' => $field_storage,
            ];
        }
    }
    asort($options);
    return $options;
}

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