You are here

function markdown_preprocess_installable_library in Markdown 8.2

Implements hook_preprocess_HOOK().

File

./markdown.module, line 158
Markdown module.

Code

function markdown_preprocess_installable_library(&$variables) {

  /** @var \Drupal\markdown\Plugin\Markdown\InstallablePluginInterface $plugin */
  $plugin = $variables['plugin'];
  $variables['installedLibrary'] = $installedLibrary = $plugin
    ->getInstalledLibrary();
  $variables['preferredLibrary'] = $preferredLibrary = $plugin
    ->getPreferredLibrary();

  /** @var \Drupal\markdown\Annotation\InstallableLibrary|null $library */
  $library = isset($variables['library']) ? $variables['library'] : NULL;
  $lib = $library ?: $preferredLibrary;
  $variables['id'] = $lib ? $lib
    ->getId() : '';
  $variables['version'] = $lib ? $lib
    ->getVersionLink() ?: ($lib->versionExtra ?: $lib->version) : NULL;
  $variables['latestVersion'] = $lib ? $lib
    ->getLatestVersion() : NULL;
  $variables['status'] = $lib ? $lib
    ->getStatus() : NULL;
  $variables['statusTitle'] = $lib ? $lib
    ->getStatus(TRUE) : NULL;
  $variables['isMultiple'] = $multiple = $plugin && count($plugin
    ->getPluginDefinition()->libraries) > 1;
  $variables['isBundled'] = $plugin instanceof ExtensionInterface && $plugin
    ->isBundled();
  $variables['isPreferred'] = $multiple && $library->preferred;
  $label = $lib->customLabel ?: $lib->label ?: $lib
    ->getId();
  if ($lib->version) {
    $label .= ':' . ($lib->versionExtra ?: $lib->version);
  }
  if ($variables['isBundled']) {
    $label .= ' (' . t('bundled') . ')';
  }
  if ($variables['isPreferred'] && !$plugin
    ->isInstalled()) {
    $label .= ' (' . t('preferred') . ')';
  }
  $variables['label'] = $lib
    ->getVersionLink($lib->version, $label);
}