function shariff_library_info_alter in Shariff Social Media Buttons 8
Implements hook_library_info_alter().
Note: libraries_get_path() is deprecated and will be removed before a stable libraries Drupal 8 release. Needs update when libraries module is supporting variants. https://www.drupal.org/node/1704734
File
- ./
shariff.module, line 272 - Integrating Shariff library, providing settings form and block.
Code
function shariff_library_info_alter(&$libraries, $extension) {
if ($extension == 'shariff') {
// Define shariff library path.
$shariff_path = NULL;
$base_path = 'libraries/shariff';
if (\Drupal::hasService('library.libraries_directory_file_finder')) {
$base_path = \Drupal::service('library.libraries_directory_file_finder')
->find('shariff');
}
elseif (function_exists('libraries_get_path')) {
// Libraries API is active.
$base_path = libraries_get_path('shariff');
}
$subfolders = [
// No subfolder.
'',
// Libraries folder with build subfolder. Let's support this for legacy
// reasons.
'/build',
// Version 3 built as npm-asset appears in the dist folder.
'/dist',
];
foreach ($subfolders as $subfolder) {
if (file_exists($base_path . $subfolder . '/shariff.min.js')) {
// If Libraries API is not active we use the libraries folder in Drupal
// root.
$shariff_path = $base_path . $subfolder;
break;
}
}
// Update shariff library path.
if ($shariff_path) {
$libraries['shariff-min']['css']['component'] = [
'/' . $shariff_path . '/shariff.min.css' => [],
];
$libraries['shariff-min']['js'] = [
'/' . $shariff_path . '/shariff.complete.js' => [
'scope' => 'footer',
],
];
$libraries['shariff-complete']['css']['component'] = [
'/' . $shariff_path . '/shariff.complete.css' => [],
];
$libraries['shariff-complete']['js'] = [
'/' . $shariff_path . '/shariff.complete.js' => [
'scope' => 'footer',
],
];
$libraries['shariff-naked']['js'] = [
'/' . $shariff_path . '/shariff.complete.js' => [
'scope' => 'footer',
],
];
}
}
}