You are here

function gutenberg_help in Gutenberg 8

Same name and namespace in other branches
  1. 8.2 gutenberg.module \gutenberg_help()

Implements hook_help().

File

./gutenberg.module, line 1090
Provides integration with the Gutenberg editor.

Code

function gutenberg_help($route_name, RouteMatchInterface $route_match) {
  if ($route_name === 'help.page.gutenberg') {
    $readme_file = file_exists(__DIR__ . '/README.md') ? __DIR__ . '/README.md' : __DIR__ . '/README.txt';
    if (!file_exists($readme_file)) {
      return NULL;
    }
    $text = file_get_contents($readme_file);
    if (!\Drupal::moduleHandler()
      ->moduleExists('markdown')) {
      return '<pre>' . $text . '</pre>';
    }
    else {

      // Use 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);
      return $filter
        ->process($text, 'en');
    }
  }
  return NULL;
}