ace_editor.module in Ace Code Editor 8
Same filename and directory in other branches
This file is used to write hooks that used in the module.
File
ace_editor.moduleView source
<?php
/**
* @file
* This file is used to write hooks that used in the module.
*/
/**
* Verifies that Ace library is present.
*
* The library is searched in the directory DRUPAL_ROOT/libraries.
* DRUPAL_ROOT/libraries is recommended for storing external libraries.
* For preserving backwards compatibility, ace_editor/libraries is also checked.
*/
function ace_editor_lib_path() {
$paths_to_check = [
'/libraries',
'/' . drupal_get_path('module', 'ace_editor') . '/libraries/',
'/' . drupal_get_path('profile', \Drupal::installProfile()) . '/libraries/',
];
foreach ($paths_to_check as $path) {
if (!is_dir(DRUPAL_ROOT . $path)) {
continue;
}
$found = \Drupal::service('file_system')
->scanDirectory(DRUPAL_ROOT . $path, '/^ace\\.js/', [
'recurse' => TRUE,
]);
if ($found) {
return substr(preg_replace('/ace\\.js/', '', reset($found)->uri), strlen(DRUPAL_ROOT));
}
}
return FALSE;
}
/**
* Implements hook_library_info_build().
*
* Selects all theme and mode files from ace editor external library and add it
* to drupal library.
*/
function ace_editor_library_info_build() {
$path = ace_editor_lib_path();
// Collects all theme and mode files available.
$files = \Drupal::service('file_system')
->scanDirectory(DRUPAL_ROOT . $path, '/(theme|mode)-(.+)\\.js$/', [
'recurse' => FALSE,
]);
$libraries = [];
foreach ($files as $file_info) {
$asset = explode('-', $file_info->name);
$library_name = $asset[0] . '.' . $asset[1];
$libraries[$library_name] = $path . $file_info->filename;
}
$libs = [];
foreach ($libraries as $key => $value) {
$libs[$key] = [
'js' => [
$value => [],
],
];
}
return $libs;
}
/**
* Implements hook_library_info_alter().
*/
function ace_editor_library_info_alter(&$libraries, $extension) {
if ($extension == 'ace_editor') {
$library_path = ace_editor_lib_path();
$libraries['primary']['js'][$library_path . 'ace.js'] = [
'weight' => -2,
];
$config = \Drupal::config('ace_editor.settings')
->get();
if ($config['auto_complete']) {
$libraries['primary']['js'][$library_path . 'ext-language_tools.js'] = [
'weight' => -2,
];
}
$libraries['formatter']['js'][$library_path . 'ace.js'] = [
'weight' => -2,
];
$libraries['filter']['js'][$library_path . 'ace.js'] = [
'weight' => -2,
];
}
}
Functions
Name | Description |
---|---|
ace_editor_library_info_alter | Implements hook_library_info_alter(). |
ace_editor_library_info_build | Implements hook_library_info_build(). |
ace_editor_lib_path | Verifies that Ace library is present. |