You are here

public function CustomFormatters::getDerivativeDefinitions in Custom Formatters 8.3

Gets the definition of all derivatives of a base plugin.

Parameters

array $base_plugin_definition: The definition array of the base plugin.

Return value

array An array of full derivative definitions keyed on derivative id.

Overrides DeriverBase::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

src/Plugin/Derivative/CustomFormatters.php, line 24

Class

CustomFormatters
Retrieves field formatter plugin definitions for all custom formatters.

Namespace

Drupal\custom_formatters\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $formatters = \Drupal::entityTypeManager()
    ->getStorage('formatter')
    ->loadMultiple();

  /** @var \Drupal\custom_formatters\FormatterInterface $formatter */
  foreach ($formatters as $formatter) {
    if ($formatter
      ->get('status')) {
      $this->derivatives[$formatter
        ->id()] = $base_plugin_definition;
      $this->derivatives[$formatter
        ->id()]['label'] = t($this
        ->getLabel($formatter
        ->label()));
      $this->derivatives[$formatter
        ->id()]['field_types'] = $formatter
        ->get('field_types');
      $this->derivatives[$formatter
        ->id()]['formatter'] = $formatter
        ->id();
      $this->derivatives[$formatter
        ->id()]['config_dependencies'] = $formatter
        ->getDependencies();
      $this->derivatives[$formatter
        ->id()]['config_dependencies']['config'][] = $formatter
        ->getConfigDependencyName();
    }
  }
  return parent::getDerivativeDefinitions($base_plugin_definition);
}