You are here

public function SkinYamlDirectoryDiscovery::getDefinitions in Skinr 8.2

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 YamlDiscovery::getDefinitions

See also

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

File

src/Plugin/Discovery/SkinYamlDirectoryDiscovery.php, line 52
Contains \Drupal\skinr\Plugin\Discovery\SkinYamlDirectoryDiscovery.

Class

SkinYamlDirectoryDiscovery
Allows YAML files to define plugin definitions.

Namespace

Drupal\skinr\Plugin\Discovery

Code

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

  // Flatten definitions into what's expected from plugins.
  // @todo Fix translatable to work for multi-levels.
  $definitions = array();
  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 + array(
        'provider' => $provider,
        'id' => $id,
      );
    }
  }
  return $definitions;
}