You are here

public function YamlDiscovery::getDefinitions in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Plugin/Discovery/YamlDiscovery.php \Drupal\Core\Plugin\Discovery\YamlDiscovery::getDefinitions()

Gets the definition of all plugins for this type.

Return value

mixed[] An array of plugin definitions (empty array if no definitions were found). Keys are plugin IDs.

Overrides DiscoveryTrait::getDefinitions

See also

\Drupal\Core\Plugin\FilteredPluginManagerInterface::getFilteredDefinitions()

1 call to YamlDiscovery::getDefinitions()
YamlDiscoveryDecorator::getDefinitions in core/lib/Drupal/Core/Plugin/Discovery/YamlDiscoveryDecorator.php
Gets the definition of all plugins for this type.
1 method overrides YamlDiscovery::getDefinitions()
YamlDiscoveryDecorator::getDefinitions in core/lib/Drupal/Core/Plugin/Discovery/YamlDiscoveryDecorator.php
Gets the definition of all plugins for this type.

File

core/lib/Drupal/Core/Plugin/Discovery/YamlDiscovery.php, line 74

Class

YamlDiscovery
Allows YAML files to define plugin definitions.

Namespace

Drupal\Core\Plugin\Discovery

Code

public function getDefinitions() {
  $plugins = $this->discovery
    ->findAll();

  // Flatten definitions into what's expected from plugins.
  $definitions = [];
  foreach ($plugins as $provider => $list) {
    foreach ($list as $id => $definition) {

      // Add TranslatableMarkup.
      foreach ($this->translatableProperties as $property => $context_key) {
        if (isset($definition[$property])) {
          $options = [];

          // Move the t() context from the definition to the translation
          // wrapper.
          if ($context_key && isset($definition[$context_key])) {
            $options['context'] = $definition[$context_key];
            unset($definition[$context_key]);
          }
          $definition[$property] = new TranslatableMarkup($definition[$property], [], $options);
        }
      }

      // Add ID and provider.
      $definitions[$id] = $definition + [
        'provider' => $provider,
        'id' => $id,
      ];
    }
  }
  return $definitions;
}