You are here

public function OnlyOneModuleHandler::getModuleHelpPageLink in Allow a content type only once (Only One) 8

Returns a link to the module help page.

Parameters

string $module_machine_name: The module machine name.

string $module_name_alternate: Alternate module name to use if the module is not present in the site.

string|false $emphasize: Use this parameter to wrap with <em> tags the module name if the module is not installed or not present in the site.

Return value

string Returns a link to the module help page if the module is installed, the alternate module name otherwise.

Overrides OnlyOneModuleHandlerInterface::getModuleHelpPageLink

File

src/OnlyOneModuleHandler.php, line 56

Class

OnlyOneModuleHandler
Class OnlyOne.

Namespace

Drupal\onlyone

Code

public function getModuleHelpPageLink($module_machine_name, $module_name_alternate, $emphasize = FALSE) {

  // Getting all the modules information.
  $modules = $this->moduleExtensionList
    ->getAllInstalledInfo();

  // Checking if the module is present in the site.
  if (isset($modules[$module_machine_name])) {

    // Getting the module name.
    $module_name = $modules[$module_machine_name]['name'];

    // If the module is installed and implement the hook_help.
    if (in_array($module_machine_name, $this->moduleHandler
      ->getImplementations('help'))) {

      // Creating the link.
      $build = [
        '#type' => 'link',
        '#title' => $module_name,
        '#url' => Url::fromRoute('help.page', [
          'name' => $module_machine_name,
        ]),
        '#cache' => [
          'tags' => [
            'config:core.extension',
          ],
        ],
      ];

      // Rendering.
      $output = $this->renderer
        ->render($build);
    }
    else {
      $output = $emphasize ? Markup::create('<em>' . $module_name . '</em>') : $module_name;
    }
  }
  else {

    // As the module is not present we use a alternate string.
    $output = $emphasize ? Markup::create('<em>' . $module_name_alternate . '</em>') : $module_name_alternate;
  }
  return $output;
}