You are here

ckeditor_codemirror.module in CKEditor CodeMirror 8.2

Same filename and directory in other branches
  1. 8 ckeditor_codemirror.module
  2. 7 ckeditor_codemirror.module

Main code for CKEditor CodeMirror module.

File

ckeditor_codemirror.module
View source
<?php

/**
 * @file
 * Main code for CKEditor CodeMirror module.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function ckeditor_codemirror_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.ckeditor_codemirror':
      $text = file_get_contents(dirname(__FILE__) . '/README.md');
      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;
}

/**
 * Gets the path of a CKEditor CodeMirror library.
 *
 * @return bool|string
 *   The path to the specified library or FALSE if the library wasn't found.
 */
function _ckeditor_codemirror_get_library_path() {
  $library_names = [
    // README.txt say to use 'ckeditor_codemirror'.
    'ckeditor_codemirror',
    // Old README.txt used 'ckeditor-codemirror'.
    'ckeditor-codemirror',
    // The Webform module is using 'ckeditor.codemirror'.
    'ckeditor.codemirror',
  ];
  foreach ($library_names as $library_name) {
    if (file_exists('libraries/' . $library_name)) {
      return 'libraries/' . $library_name;
    }
  }
  return FALSE;
}

Functions

Namesort descending Description
ckeditor_codemirror_help Implements hook_help().
_ckeditor_codemirror_get_library_path Gets the path of a CKEditor CodeMirror library.