FieldStorageAddForm::getExistingFieldStorageOptions

protected 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.

File

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

Class

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

Namespace

Drupal\field_ui\Form

Code

protected function getExistingFieldStorageOptions() {
  $options = array();
  // Load the field_storages and build the list of options.
  $field_types = $this->fieldTypePluginManager->getDefinitions();
  foreach ($this->entityManager->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', array(
        '@type' => $field_types[$field_type]['label'],
        '@field' => $field_name,
      ));
    }
  }
  asort($options);

  return $options;
}
doc_Drupal
2016-10-29 09:12:08
Comments
Leave a Comment

Please login to continue.