function sharemessage_library_info_alter in Share Message 8
Implements hook_library_info_alter().
File
- ./
sharemessage.module, line 65 - New Sharing Module.
Code
function sharemessage_library_info_alter(&$libraries, $extension) {
if ($extension != 'sharemessage') {
return;
}
// Add the profile id to the URL if present.
$profile_id = \Drupal::config('sharemessage.addthis')
->get('addthis_profile_id');
if ($profile_id) {
$libraries['addthis']['js']['//s7.addthis.com/js/300/addthis_widget.js#pubid=' . $profile_id] = $libraries['addthis']['js']['//s7.addthis.com/js/300/addthis_widget.js'];
unset($libraries['addthis']['js']['//s7.addthis.com/js/300/addthis_widget.js']);
}
// Get the correct path of the Sharrre js file (the user needs to manually
// put the jquery.sharrre.min.js in libraries/sharrre folder or set the url
// in the settings).
$config = \Drupal::config('sharemessage.sharrre');
if ($library_url = $config
->get('library_url')) {
// Cloud hosted player, use external JavaScript.
$libraries['sharrre']['js'][$library_url] = [
'type' => 'external',
];
}
elseif (\Drupal::moduleHandler()
->moduleExists('libraries')) {
$info = libraries_detect('sharrre');
$libraries['sharrre'] += [
'version' => $info['installed'] ? $info['version'] : 'web-hosted',
];
if ($info['installed']) {
// Because the library is self hosted, use files from library definition.
if (!empty($info['files']['js'])) {
foreach ($info['files']['js'] as $data => $option) {
if (is_numeric($data)) {
$option = "/{$info['library path']}/{$option}";
}
elseif (empty($option['type']) || $option['type'] == 'file') {
$data = "/{$info['library path']}/{$data}";
}
$libraries['sharrre']['js'][$data] = $option;
}
}
}
}
if (\Drupal::moduleHandler()
->moduleExists('libraries')) {
$info = libraries_detect('socialshareprivacy');
$libraries['socialshareprivacy'] += [
'version' => $info['version'],
];
if ($info['installed']) {
$libraries['socialshareprivacy']['library path'] = $info['library path'];
$path_js = '/' . $info['library path'] . '/jquery.socialshareprivacy.min.js';
$libraries['socialshareprivacy']['js'][$path_js] = [];
$path_css = '/' . $info['library path'] . '/stylesheets/jquery.socialshareprivacy.min.css';
$libraries['socialshareprivacy']['css']['base'][$path_css] = [];
}
}
else {
// Without libraries.module, we can't discover the location, assume it is in
// the top-level /libraries folder.
$libraries['socialshareprivacy'] += [
'version' => 'unknown',
];
$libraries['socialshareprivacy']['library path'] = '/libraries/socialshareprivacy';
$libraries['socialshareprivacy']['js']['/libraries/socialshareprivacy/jquery.socialshareprivacy.min.js'] = [];
$libraries['socialshareprivacy']['css']['base']['/libraries/socialshareprivacy/stylesheets/jquery.socialshareprivacy.min.css'] = [];
}
}