Skip to content
Snippets Groups Projects

Issue #3230415: Call to deprecated function libraries_detect():

Open Shaun Laws requested to merge issue/lite-3230415:8.x-1.x into 8.x-1.x
Files
6
@@ -25,9 +25,7 @@ class Lite extends CKEditorPluginBase {
* {@inheritdoc}
*/
public function getFile() {
$library = libraries_detect('lite');
return $library['library path'] . '/plugin.js';
return $this->getLibraryPath() . '/plugin.js';
}
/**
@@ -48,34 +46,74 @@ class Lite extends CKEditorPluginBase {
* {@inheritdoc}
*/
public function getButtons() {
$library = libraries_detect('lite');
$libraryPath = $this->getLibraryPath();
return array(
'lite-acceptall' => array(
'label' => t('Accept all changes'),
'image' => $library['library path'] . '/icons/lite-acceptall.png',
'image' => $libraryPath . '/icons/lite-acceptall.png',
),
'lite-rejectall' => array(
'label' => t('Reject all changes'),
'image' => $library['library path'] . '/icons/lite-rejectall.png',
'image' => $libraryPath . '/icons/lite-rejectall.png',
),
'lite-acceptone' => array(
'label' => t('Accept change'),
'image' => $library['library path'] . '/icons/lite-acceptone.png',
'image' => $libraryPath . '/icons/lite-acceptone.png',
),
'lite-rejectone' => array(
'label' => t('Reject change'),
'image' => $library['library path'] . '/icons/lite-rejectone.png',
'image' => $libraryPath . '/icons/lite-rejectone.png',
),
'lite-toggleshow' => array(
'label' => t('Show/hide tracked changes'),
'image' => $library['library path'] . '/icons/lite-toggleshow.png',
'image' => $libraryPath . '/icons/lite-toggleshow.png',
),
'lite-toggletracking' => array(
'label' => t('Start/stop tracking changes'),
'image' => $library['library path'] . '/icons/lite-toggletracking.png',
'image' => $libraryPath . '/icons/lite-toggletracking.png',
),
);
}
/**
* Get the CKEditor Lite library path.
*/
protected function getLibraryPath() {
// Following the logic in Drupal 8.9.x and Drupal 9.x
// ----------------------------------------------------------------------
// Issue #3096648: Add support for third party libraries in site specific
// and install profile specific libraries folders
// https://www.drupal.org/project/drupal/issues/3096648
//
// https://git.drupalcode.org/project/drupal/commit/1edf15f
// -----------------------------------------------------------------------
// Search sites/<domain>/*.
$directories[] = \Drupal::service('site.path') . "/libraries/";
// Always search the root 'libraries' directory.
$directories[] = 'libraries/';
// Installation profiles can place libraries into a 'libraries' directory.
if ($installProfile = \Drupal::installProfile()) {
$profile_path = drupal_get_path('profile', $installProfile);
$directories[] = "$profile_path/libraries/";
}
foreach ($directories as $dir) {
if (file_exists(DRUPAL_ROOT . '/' . $dir . 'lite/plugin.js')) {
return $dir . 'lite';
}
}
return 'libraries/lite';
}
/**
* Get the CKEditor Lite library URL.
*/
protected function getLibraryUrl() {
$originUrl = \Drupal::request()->getSchemeAndHttpHost() . \Drupal::request()->getBaseUrl();
return $originUrl . '/' . $this->getLibraryPath();
}
}
Loading