You are here

class Hint in Advanced Help Hint 8

The Hint class produces a hint string for hook_help().

Hierarchy

  • class \Drupal\advanced_help_hint\Hint

Expanded class hierarchy of Hint

1 string reference to 'Hint'
advanced_help_hint.services.yml in ./advanced_help_hint.services.yml
advanced_help_hint.services.yml
1 service uses Hint
advanced_help_hint.gethint in ./advanced_help_hint.services.yml
Drupal\advanced_help_hint\Hint

File

src/Hint.php, line 12

Namespace

Drupal\advanced_help_hint
View source
class Hint {

  /**
   * Assemples and returns the hint.
   */
  public function produceHint($project, $doclink = NULL, $repo = FALSE) {
    $output = '';
    if ($doclink) {
      $options = [
        'attributes' => [
          'title' => t('Link to documentation of the project online.'),
        ],
      ];
      $link = Link::fromTextAndUrl(t('online documentation'), Url::fromUri($doclink, $options))
        ->toString();
      $ss = new FormattableMarkup(t('Please see the @url.'), [
        '@url' => $link,
      ]);
      $output .= $ss;
    }
    if (\Drupal::moduleHandler()
      ->moduleExists('advanced_help')) {
      $plugin_manager = \Drupal::service('plugin.manager.advanced_help');
      $topics = $plugin_manager
        ->getTopics();
      if (!empty($output)) {
        $output = $output . ' ';
      }
      if (!$repo) {
        $output .= t("No additional help available for “!project”.", array(
          '!project' => $project,
        ));

        // Nothing more to do.
        return $output;
      }
      if (!isset($topics[$project])) {
        $output .= t("Expected to find some help for project “@project” in the project's help-directory, but could not locate any.", array(
          '@project' => $project,
        ));

        // Nothing more to do.
        return $output;
      }
      $file = key($topics[$project]);
      $ext = pathinfo($file, PATHINFO_EXTENSION);
      $helpPath = '/admin/help/ah/' . $project;
      if (empty($ext)) {
        $options = [
          'attributes' => [
            'title' => t('Link to advanced help'),
          ],
        ];
        $link = Link::fromTextAndUrl(t('advanced help framework'), Url::fromUri('base:' . $helpPath, $options))
          ->toString();
        $ss = new FormattableMarkup(t('Additional help is provided by the @help.'), [
          '@help' => $link,
        ]);
        $output .= $ss;
      }
      else {
        $options = [
          'attributes' => [
            'title' => t('Link to included documentation.'),
          ],
        ];
        $link = Link::fromTextAndUrl(t('README'), Url::fromUri('base:' . $helpPath, $options))
          ->toString();
        $ss = new FormattableMarkup(t("Additional help is available in the project's “@readme” file."), [
          '@readme' => $link,
        ]);
        $output .= $ss;
      }
    }
    elseif ($repo) {
      if (!empty($output)) {
        $output = $output . ' ';
      }

      // Since advanced_help is not enabled we can't check to make sure help is available.
      $options = [
        'attributes' => [
          'title' => t('Link to the Advanced Help project.'),
        ],
      ];
      $link = Link::fromTextAndUrl(t('Advanced Help'), Url::fromUri('https://www.drupal.org/project/advanced_help', $options))
        ->toString();
      $ss = new FormattableMarkup(t('If you install the @advhelp module, additional help may be available.'), [
        '@advhelp' => $link,
      ]);
      $output .= $ss;
    }
    return $output;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Hint::produceHint public function Assemples and returns the hint.