Interim commit.
[yaffs-website] / web / modules / contrib / blazy / tests / modules / blazy_test / blazy_test.module
1 <?php
2
3 /**
4  * @file
5  * Testing various Blazy hooks, etc.
6  */
7
8 /**
9  * Implements hook_theme().
10  */
11 function blazy_test_theme() {
12   return ['blazy_test' => ['render element' => 'element']];
13 }
14
15 /**
16  * Prepares variables for blazy-test.html.twig templates.
17  */
18 function template_preprocess_blazy_test(&$variables) {
19   $element = $variables['element'];
20
21   $variables['content'] = $element['#children'];
22   $variables['settings'] = isset($element['#settings']) ? $element['#settings'] : [];
23 }
24
25 /**
26  * Implements hook_blazy_attach_alter().
27  */
28 function blazy_test_blazy_attach_alter(array &$load, array $settings = []) {
29   if (!empty($settings['blazy_test'])) {
30     $load['library'][] = 'foo/fake_library';
31
32     $manager = \Drupal::service('blazy.manager');
33     $template = ['#theme' => 'blazy_test'];
34     $load['drupalSettings']['blazy_test'] = [
35       'options' => ['slideshow' => TRUE],
36       'container' => $manager->getRenderer()->renderPlain($template),
37     ];
38   }
39 }
40
41 /**
42  * Implements hook_blazy_attach_alter().
43  */
44 function blazy_test_blazy_lightboxes_alter(array &$lightboxes) {
45   $lightboxes[] = 'blazy_test';
46 }
47
48 /**
49  * Implements hook_blazy_attach_alter().
50  */
51 function blazy_test_blazy_alter(array &$image, array $settings = []) {
52   if (!empty($settings['media_switch']) && $settings['media_switch'] == 'blazy_test') {
53     $image['#pre_render'][] = 'blazy_test_pre_render';
54   }
55 }
56
57 /**
58  * #pre_render callback: Sets blazy_test related URL attributes.
59  */
60 function blazy_test_pre_render($image) {
61   $settings = isset($image['#settings']) ? $image['#settings'] : [];
62
63   // Video's HREF points to external site, adds URL to local image.
64   if (!empty($settings['box_url']) && !empty($settings['embed_url'])) {
65     $image['#url_attributes']['data-box-url'] = $settings['box_url'];
66   }
67
68   return $image;
69 }
70
71 /**
72  * Implements hook_hook_info().
73  */
74 function blazy_test_hook_info() {
75   $hooks['blazy_test_skins_info'] = ['group' => 'blazy_test'];
76   return $hooks;
77 }
78
79 if (!function_exists('token_theme')) {
80
81   /**
82    * Dummy function.
83    */
84   function token_theme() {
85     // Empty block to satisfy coder.
86   }
87
88 }
89
90 if (!function_exists('video_embed_media_media_bundle_insert')) {
91
92   /**
93    * Dummy function.
94    */
95   function video_embed_media_media_bundle_insert() {
96     // Empty block to satisfy coder.
97   }
98
99 }