You are here

popup_message.module in Popup message 8

Same filename and directory in other branches
  1. 6 popup_message.module
  2. 7 popup_message.module

Contains \Drupal\popup_message\popup_message.module.

File

popup_message.module
View source
<?php

/**
 * @file
 * Contains \Drupal\popup_message\popup_message.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function popup_message_help($route_name, RouteMatchInterface $route_match) {
  if ($route_name === 'help.page.popup_message') {
    $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;
}

/**
 * Implements hook_library_info_alter().
 */
function popup_message_library_info_alter(array &$libraries, $extension) {
  $config_popup = \Drupal::configFactory()
    ->getEditable('popup_message.settings');
  $style = $config_popup
    ->get('style');
  if ($extension === 'popup_message') {
    $libraries['popup_message_style']['css']['base'] = [];
    $libraries['popup_message_style']['css']['base']['styles' . '/' . $style] = [];
  }
}