Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / advagg / advagg.api.php
1 <?php
2
3 /**
4  * @file
5  * Hooks provided by the AdvAgg module.
6  */
7
8 /**
9  * @defgroup advagg_hooks Advanced Aggregates Hooks
10  *
11  * @{
12  * Hooks for modules to implement to extend or modify Advanced Aggregates.
13  *
14  * @see https://api.drupal.org/api/drupal/includes%21module.inc/group/hooks/7.x
15  */
16
17 /**
18  * Allow other modules to modify the aggregate groups.
19  *
20  * Called once per page at aggregation time (if not cached).
21  * Should be in MODULENAME.advagg.inc file.
22  *
23  * @param array $groups
24  *   The generated groups.
25  * @param string $type
26  *   The asset type ('css' or 'js').
27  *
28  * @see \Drupal\advagg\Asset\CssCollectionGrouper::group()
29  * @see \Drupal\advagg\Asset\JsCollectionGrouper::group()
30  * @see advagg_bundler_advagg_aggregate_grouping_alter()
31  */
32 function hook_advagg_aggregate_grouping_alter(array &$groups, $type) {
33   $max = 4;
34   $modifiable = [];
35   $files = 0;
36   foreach ($groups as $key => $group) {
37     if (isset($group['type'], $group['preprocess']) && $group['type'] == 'file' && $group['preprocess']) {
38       $modifiable[$key] = $group;
39       $modifiable[$key]['order'] = $key;
40       $modifiable[$key]['file_count'] = count($group['items']);
41       $files += count($group['items']);
42     }
43   }
44
45   // If more bundles than $max return. $groups is already set to least
46   // possible number of groups with current sort. Enabling sort external first
47   // may help decrease number of bundles.
48   if (count($modifiable) > $max || !$modifiable) {
49     return;
50   }
51
52   $target_files = ceil($files / $max);
53   $final_groups = [];
54   $bundles = 0;
55   foreach ($groups as $key => $group) {
56     if (!isset($modifiable[$key]) || $bundles == $max) {
57       $final_groups[] = $group;
58       continue;
59     }
60     $splits = round($modifiable[$key]['file_count'] / $target_files);
61     if ($splits < 2) {
62       $final_groups[] = $group;
63       $bundles++;
64       continue;
65     }
66     $chunks = array_chunk($group['items'], $target_files);
67     foreach ($chunks as $chunk) {
68       $group['items'] = $chunk;
69       $final_groups[] = $group;
70       $bundles++;
71     }
72   }
73
74   $groups = $final_groups;
75 }
76
77 /**
78  * Allow other modules to add in their own settings and hooks.
79  *
80  * @param array $aggregate_settings
81  *   An associative array of hooks and settings used.
82  *
83  * @see advagg_current_hooks_hash_array()
84  * @see advagg_js_minify_advagg_current_hooks_hash_array_alter()
85  */
86 function hook_advagg_current_hooks_hash_array_alter(array &$aggregate_settings) {
87   $aggregate_settings['variables']['advagg_js_minify'] = \Drupal::config('advagg_js_minify.settings')->get();
88 }
89
90 /**
91  * Allow other modules to modify the contents of individual CSS files.
92  *
93  * Called once per file at aggregation time.
94  *
95  * @param string $data
96  *   File contents. Depending on settings/modules these may be minified.
97  * @param array $css_asset
98  *   Asset array.
99  *
100  * @see \Drupal\advagg\Asset\CssCollectionOptimizer::optimize()
101  */
102 function hook_advagg_css_contents_alter(&$data, array $css_asset) {
103   // Remove all font-style rules applying italics.
104   preg_replace("/(.*)(font-style\s*:.*italic)(.*)/m", "$0 --> $1 $3", $data);
105 }
106
107 /**
108  * Allow other modules to modify the contents of individual JavaScript files.
109  *
110  * Called once per file at aggregation time.
111  *
112  * @param string $contents
113  *   Raw file data.
114  * @param array $js_asset
115  *   Asset array.
116  *
117  * @see \Drupal\advagg\Asset\JsCollectionOptimizer::optimize()
118  */
119 function hook_advagg_js_contents_alter(&$contents, array $js_asset) {
120   if ($js_asset['data'] == 'modules/advagg/advagg.admin.js') {
121     $contents = str_replace('AdvAgg Bypass Cookie Removed', 'Advanced Aggregates Cookie Removed', $contents);
122   }
123 }
124
125 /**
126  * Let other modules add/alter additional information about file passed in.
127  *
128  * @param string $file
129  *   The file path/name.
130  * @param array $data
131  *   An associative array of metadata on the file.
132  * @param array $cached
133  *   What data was found in the database (if any).
134  *
135  * @see Drupal\advagg\State\Files::scanFiles()
136  */
137 function hook_advagg_scan_file_alter($file, array $data, array $cached) {
138   $data['chars'] = strlen($data['content']);
139 }
140
141 /**
142  * Tell advagg about other hooks related to advagg.
143  *
144  * @param array $hooks
145  *   Array of hooks related to advagg.
146  * @param bool $all
147  *   If FALSE get only the subset of hooks that alter the filename/contents.
148  *
149  * @see advagg_hooks_implemented()
150  * @see advagg_bundler_advagg_hooks_implemented_alter()
151  */
152 function hook_advagg_hooks_implemented_alter(array &$hooks, $all) {
153   if ($all) {
154     $hooks['advagg_bundler_analysis_alter'] = [];
155   }
156 }
157
158 /**
159  * Allow other modules to modify the path to save aggregates to.
160  *
161  * @param string $path
162  *   The currently set folder to save the aggregated assets to.
163  *
164  * @see Drupal\advagg\Asset\AssetDumper::preparePath()
165  * @see advagg_mod_advagg_asset_path_alter()
166  */
167 function hook_advagg_asset_path_alter(&$path, $extension) {
168   if ($extension == 'js') {
169     $path = 'public://javascript/';
170   }
171 }
172
173 /**
174  * Let other modules modify the analysis array before it is used.
175  *
176  * @param array $analysis
177  *   An associative array; filename -> data.
178  *
179  * @see advagg_bundler_analysis()
180  */
181 function hook_advagg_bundler_analysis_alter(array &$analysis) {
182   foreach ($analysis as $filename => &$data) {
183     if ($filename) {
184       // This is the filename.
185     }
186
187     // This changes often; 604800 is 1 week.
188     if ($data['changes'] > 10 && $data['mtime'] >= REQUEST_TIME - 604800) {
189       // Modify the group hash so this doesn't end up in a big aggregate.
190       $data['group_hash'];
191     }
192   }
193   unset($data);
194 }
195
196 /**
197  * @} End of "defgroup advagg_hooks".
198  */