You are here

function collapse_text_help in Collapse Text 8

Same name and namespace in other branches
  1. 2.0.x collapse_text.module \collapse_text_help()

Implements hook_help().

File

./collapse_text.module, line 56
It is an input filter that allows text to be collapsible.

Code

function collapse_text_help($route_name) {
  switch ($route_name) {
    case 'help.page.collapse_text':
      $readme_file = __DIR__ . '/README.md';
      if (!file_exists($readme_file)) {
        return NULL;
      }
      $text = file_get_contents($readme_file);

      // If the Markdown module is installed...
      if (\Drupal::moduleHandler()
        ->moduleExists('markdown') === TRUE) {

        // Uses the Markdown filter to render the README.
        $filter_manager = \Drupal::service('plugin.manager.filter');
        $settings = \Drupal::configFactory()
          ->get('markdown.settings')
          ->getRawData();
        $config = [
          'settings' => $settings,
        ];
        $filter = $filter_manager
          ->createInstance('markdown', $config);
        $output = $filter
          ->process($text, 'en');
      }
      else {

        // Outputs the escaped README in plain text (watchout for html tags).
        $output = '<pre>' . Html::escape($text) . '</pre>';
      }

      // Adds a link to the Drupal.org documentation pages.
      $output .= t('<p>See the <a href=":documentation">documentation pages</a> on Drupal.org for more information.</p>', [
        ':documentation' => 'https://git.drupalcode.org/project/collapse_text',
      ]);
      return $output;
  }
}