You are here

protected function InstallablePluginManager::getRuntimeDefinitions in Markdown 8.2

Retrieves the runtime definitions.

@noinspection PhpDocMissingThrowsInspection

Return value

\Drupal\markdown\Annotation\InstallablePlugin[] The runtime definitions.

1 call to InstallablePluginManager::getRuntimeDefinitions()
InstallablePluginManager::getDefinitions in src/PluginManager/InstallablePluginManager.php
Gets the definition of all plugins for this type.

File

src/PluginManager/InstallablePluginManager.php, line 373

Class

InstallablePluginManager
Installable Plugin Manager.

Namespace

Drupal\markdown\PluginManager

Code

protected function getRuntimeDefinitions() {

  // Ensure the class has an array key set, defaulted to NULL.
  if (!array_key_exists(static::class, static::$runtimeDefinitions)) {
    static::$runtimeDefinitions[static::class] = NULL;
  }

  // Retrieve cached runtime definitions.
  static::$runtimeDefinitions[static::class] = $this
    ->getCachedDefinitions(TRUE);

  // Build the runtime definitions.
  if (!isset(static::$runtimeDefinitions[static::class])) {

    // Retrieve normal definitions.
    static::$runtimeDefinitions[static::class] = parent::getDefinitions();

    // Validate runtime definition requirements.

    /* @var \Drupal\markdown\Annotation\InstallablePlugin $definition */
    foreach (static::$runtimeDefinitions[static::class] as $definition) {
      $definition
        ->validate(TRUE);
    }

    // Alter runtime definitions.
    $this
      ->alterDefinitions(static::$runtimeDefinitions[static::class], TRUE);

    // Normalize any callbacks provided.
    try {
      static::normalizeCallables(static::$runtimeDefinitions[static::class]);
    } catch (MarkdownUnexpectedValueException $exception) {
      $plugin_id = array_reverse($exception
        ->getParents())[0];
      $annotation = array_reverse(explode('\\', $this->pluginDefinitionAnnotationName))[0];
      throw new InvalidPluginDefinitionException($plugin_id, sprintf('Invalid callback defined in @%s. %s.', $annotation, $exception
        ->getMessage()), 0, isset($e) ? $e : NULL);
    }

    // Re-validate runtime definition requirements after alterations.

    /* @var \Drupal\markdown\Annotation\InstallablePlugin $definition */
    foreach (static::$runtimeDefinitions[static::class] as $plugin_id => $definition) {
      $definition
        ->validate(TRUE);
    }

    // Sort the runtime definitions.
    $this
      ->sortDefinitions(static::$runtimeDefinitions[static::class]);

    // Cache the runtime definitions.
    $this
      ->setCachedDefinitions(static::$runtimeDefinitions[static::class], TRUE);
  }

  // Runtime definitions should always be the active definitions.
  $this->definitions = static::$runtimeDefinitions[static::class];
  return $this->definitions;
}