You are here

public function InstallablePluginManager::processDefinition in Markdown 8.2

Performs extra processing on plugin definitions.

By default we add defaults for the type to the definition. If a type has additional processing logic they can do that by replacing or extending the method.

Overrides DefaultPluginManager::processDefinition

4 calls to InstallablePluginManager::processDefinition()
AllowedHtmlManager::processDefinition in src/PluginManager/AllowedHtmlManager.php
Performs extra processing on plugin definitions.
ExtensionManager::processDefinition in src/PluginManager/ExtensionManager.php
Performs extra processing on plugin definitions.
InstallablePluginManager::findDefinitions in src/PluginManager/InstallablePluginManager.php
Finds plugin definitions.
ParserManager::processDefinition in src/PluginManager/ParserManager.php
Performs extra processing on plugin definitions.
3 methods override InstallablePluginManager::processDefinition()
AllowedHtmlManager::processDefinition in src/PluginManager/AllowedHtmlManager.php
Performs extra processing on plugin definitions.
ExtensionManager::processDefinition in src/PluginManager/ExtensionManager.php
Performs extra processing on plugin definitions.
ParserManager::processDefinition in src/PluginManager/ParserManager.php
Performs extra processing on plugin definitions.

File

src/PluginManager/InstallablePluginManager.php, line 456

Class

InstallablePluginManager
Installable Plugin Manager.

Namespace

Drupal\markdown\PluginManager

Code

public function processDefinition(&$definition, $pluginId) {
  if (!$definition instanceof InstallablePlugin) {
    return;
  }

  // Normalize the class.
  $definition
    ->setClass(static::normalizeClassName($definition
    ->getClass()));

  // Convert legacy "installed" property to "libraries".
  // @todo Deprecated functionality, remove before 3.0.0.
  $this
    ->convertInstalledToLibraries($definition);

  // When no libraries or requirements are specified, create a new library
  // from the definition itself and treat it as its own standalone library.
  if (!$definition->libraries && !$definition->requirements && !$definition->runtimeRequirements && !$definition->requirementViolations) {
    $definition->libraries[] = InstallableLibrary::create($definition);
  }

  // Process libraries.
  $preferred = FALSE;
  $preferredWeight = -1;
  $seenIds = [];
  foreach ($definition->libraries as $key => $library) {
    $id = $library
      ->getId();
    if (!isset($seenIds[$id])) {
      $seenIds[$id] = $library;
    }
    else {
      unset($definition->libraries[$key]);
    }

    /* @noinspection PhpUnhandledExceptionInspection */
    $this
      ->processLibraryDefinition($definition, $library, $preferred);
    $preferredWeight = min($preferredWeight, $library->weight);
  }

  // If no library was preferred, default to the first library defined.
  if (!$preferred && ($library = reset($definition->libraries))) {
    $library->preferred = TRUE;
    $library->weight = $preferredWeight;
  }

  // Sort the library definitions.
  $this
    ->sortDefinitions($definition->libraries);

  // Merge in the installed or preferred library into the actual plugin.
  if ($library = $definition
    ->getInstalledLibrary() ?: $definition
    ->getPreferredLibrary()) {

    // Merge library into plugin definition, excluding certain properties.
    $definition
      ->merge($library, [
      'ui',
      'weight',
    ]);

    // Set default URL for plugin based on the installed/preferred library.
    if (!$definition->url && ($url = $library
      ->getUrl())) {
      $definition->url = $url
        ->toString();
    }
  }
}