You are here

public function DiffBuilderManager::getApplicablePluginOptions in Diff 8

Gets the applicable plugin options for a given field.

Loop over the plugins that can be applied to the field and builds an array of possible plugins based on each plugin weight.

Parameters

FieldStorageDefinitionInterface $field_definition: The field storage definition.

Return value

array The plugin option for the given field based on plugin weight.

1 call to DiffBuilderManager::getApplicablePluginOptions()
DiffBuilderManager::getSelectedPluginForFieldStorageDefinition in src/DiffBuilderManager.php
Selects a default plugin for a field storage definition.

File

src/DiffBuilderManager.php, line 209

Class

DiffBuilderManager
Plugin type manager for field diff builders.

Namespace

Drupal\diff

Code

public function getApplicablePluginOptions(FieldStorageDefinitionInterface $field_definition) {
  $plugins = $this
    ->getPluginDefinitions();

  // Build a list of all diff plugins supporting the field type of the field.
  $plugin_options = [];
  if (isset($plugins[$field_definition
    ->getType()])) {

    // Sort the plugins based on their weight.
    uasort($plugins[$field_definition
      ->getType()], 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
    foreach ($plugins[$field_definition
      ->getType()] as $id => $weight) {
      $definition = $this
        ->getDefinition($id, FALSE);

      // Check if the plugin is applicable.
      if (isset($definition['class']) && in_array($field_definition
        ->getType(), $definition['field_types'])) {

        /** @var FieldDiffBuilderInterface $class */
        $class = $definition['class'];
        if ($class::isApplicable($field_definition)) {
          $plugin_options[$id] = $this
            ->getDefinitions()[$id]['label'];
        }
      }
    }
  }
  return $plugin_options;
}