You are here

public function DiffBuilderManager::getSelectedPluginForFieldStorageDefinition in Diff 8

Selects a default plugin for a field storage definition.

Checks if a plugin has been already selected for the field, otherwise chooses one between the plugins that can be applied to the field.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface $field_definition: The field storage definition.

Return value

array An array with the key type (which contains the plugin ID) and settings. The special type hidden indicates that the field should not be shown.

1 call to DiffBuilderManager::getSelectedPluginForFieldStorageDefinition()
DiffBuilderManager::createInstanceForFieldDefinition in src/DiffBuilderManager.php
Creates a plugin instance for a field definition.

File

src/DiffBuilderManager.php, line 147

Class

DiffBuilderManager
Plugin type manager for field diff builders.

Namespace

Drupal\diff

Code

public function getSelectedPluginForFieldStorageDefinition(FieldStorageDefinitionInterface $field_definition) {
  $plugin_options = $this
    ->getApplicablePluginOptions($field_definition);
  $field_key = $field_definition
    ->getTargetEntityTypeId() . '.' . $field_definition
    ->getName();

  // Start with the stored configuration, this returns NULL if there is none.
  $selected_plugin = $this->pluginsConfig
    ->get('fields.' . $field_key);

  // If there is configuration and it is a valid type or exlplicitly set to
  // hidden, then use that, otherwise try to find a suitable default plugin.
  if ($selected_plugin && (in_array($selected_plugin['type'], array_keys($plugin_options)) || $selected_plugin['type'] == 'hidden')) {
    return $selected_plugin + [
      'settings' => [],
    ];
  }
  elseif (!empty($plugin_options) && $this
    ->isFieldStorageDefinitionDisplayed($field_definition)) {
    return [
      'type' => key($plugin_options),
      'settings' => [],
    ];
  }
  else {
    return [
      'type' => 'hidden',
      'settings' => [],
    ];
  }
}