blazy_photoswipe.module in Blazy PhotoSwipe 7
Same filename and directory in other branches
Provides a simple Blazy PhotoSwipe integration.
File
blazy_photoswipe.moduleView source
<?php
/**
* @file
* Provides a simple Blazy PhotoSwipe integration.
*/
/**
* Implements hook_library().
*/
function blazy_photoswipe_library() {
$info = system_get_info('module', 'blazy_photoswipe');
$path = drupal_get_path('module', 'blazy_photoswipe');
$libraries['load'] = [
'title' => 'Blazy PhotoSwipe',
'website' => 'https://drupal.org/project/blazy_photoswipe',
'version' => empty($info['version']) ? '1.x' : $info['version'],
'js' => [
$path . '/js/blazy.photoswipe.min.js' => [
'group' => JS_DEFAULT,
],
],
'css' => [
$path . '/css/blazy.photoswipe.theme.css' => [],
],
'dependencies' => [
[
'blazy',
'lightbox',
],
[
'blazy',
'media',
],
],
];
return $libraries;
}
/**
* Implements hook_blazy_alter().
*/
function blazy_photoswipe_blazy_alter(array &$image, $settings = []) {
if (!empty($settings['media_switch']) && $settings['media_switch'] == 'photoswipe') {
$image['#pre_render'][] = 'blazy_photoswipe_pre_render';
}
}
/**
* The #pre_render callback: Sets PhotoSwipe related URL attributes.
*/
function blazy_photoswipe_pre_render($image) {
$settings = isset($image['#settings']) ? $image['#settings'] : [];
// Video's HREF points to external site, adds URL to local image.
// Cannot rely on IMG as IMG is not there when using CSS background.
if (!empty($settings['box_url']) && !empty($settings['embed_url'])) {
$image['#url_attributes']['data-box-url'] = $settings['box_url'];
}
return $image;
}
/**
* Implements hook_blazy_attach_alter().
*/
function blazy_photoswipe_blazy_attach_alter(array &$load, $attach = []) {
if (!photoswipe_assets_loaded() && !empty($attach['photoswipe'])) {
libraries_load('photoswipe');
$template = [
'#theme' => 'photoswipe_container',
];
$template = preg_replace([
'/<!--(.|\\s)*?-->/',
'/\\s+/',
], ' ', drupal_render($template));
$options = variable_get('photoswipe_settings', photoswipe_get_default_settings());
drupal_alter('blazy_photoswipe_js_options', $options, $attach);
$load['js'][] = [
'data' => [
'photoswipe' => [
'options' => $options,
'container' => trim($template),
],
],
'type' => 'setting',
];
$load['library'][] = [
'blazy_photoswipe',
'load',
];
photoswipe_assets_loaded(TRUE);
}
}
/**
* Implements hook_blazy_lightboxes_alter().
*/
function blazy_photoswipe_blazy_lightboxes_alter(array &$lightboxes) {
$lightboxes[] = 'photoswipe';
}
/**
* Implements hook_help().
*/
function blazy_photoswipe_help($path, $arg) {
if ($path == 'admin/help#blazy_photoswipe') {
$output = file_get_contents(dirname(__FILE__) . '/README.md');
return function_exists('_filter_markdown') ? _filter_markdown($output, NULL) : '<pre>' . $output . '</pre>';
}
return '';
}Functions
|
Name |
Description |
|---|---|
| blazy_photoswipe_blazy_alter | Implements hook_blazy_alter(). |
| blazy_photoswipe_blazy_attach_alter | Implements hook_blazy_attach_alter(). |
| blazy_photoswipe_blazy_lightboxes_alter | Implements hook_blazy_lightboxes_alter(). |
| blazy_photoswipe_help | Implements hook_help(). |
| blazy_photoswipe_library | Implements hook_library(). |
| blazy_photoswipe_pre_render | The #pre_render callback: Sets PhotoSwipe related URL attributes. |