function ExtensionInstallCommand::getExtensionLinks

Returns console-formatted hyperlinks for an extension's admin pages.

Return value

string[] Zero or more strings in the Symfony Console hyperlink format (<href=URL>label</>).

File

core/modules/system/src/Command/ExtensionInstallCommand.php, line 250

Class

ExtensionInstallCommand
Installs modules or themes, resolving and confirming their dependencies.

Namespace

Drupal\system\Command

Code

private function getExtensionLinks(string $machine_name, Extension $extension) : array {
  $links = [];
  // Fetch lazily: ModuleInstaller::install() rebuilds the container, and
  // resetImplementations() does not clear hookLists, so the injected handler
  // retains a stale hook list that misses newly installed modules.
  $module_handler = \Drupal::moduleHandler();
  if ($module_handler->moduleExists('help') && $module_handler->hasImplementations('help', $machine_name)) {
    $url = Url::fromRoute('help.page', [
      'name' => $machine_name,
    ])->setAbsolute()
      ->toString();
    $links[] = sprintf('<href=%s>%s</>', $url, $this->t('Help'));
  }
  // Fetched lazily rather than via constructor injection because
  // ModuleInstaller::install() triggers a container rebuild, which would
  // leave an injected instance stale.
  if (\Drupal::hasService(PermissionHandlerInterface::class) && \Drupal::service(PermissionHandlerInterface::class)->moduleProvidesPermissions($machine_name)) {
    $url = Url::fromRoute('user.admin_permissions.module', [
      'modules' => $machine_name,
    ])->setAbsolute()
      ->toString();
    $links[] = sprintf('<href=%s>%s</>', $url, $this->t('Permissions'));
  }
  if (isset($extension->info['configure'])) {
    $params = $extension->info['configure_parameters'] ?? [];
    $url = Url::fromRoute($extension->info['configure'], $params)
      ->setAbsolute()
      ->toString();
    $links[] = sprintf('<href=%s>%s</>', $url, $this->t('Configure'));
  }
  return $links;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.