95ea0c9e2adcb9c2615cfc6a6d1c59048f56dbff
[yaffs-website] / web / modules / contrib / advagg / advagg_bundler / advagg_bundler.module
1 <?php
2
3 /**
4  * @file
5  * Advanced aggregation bundler module.
6  */
7
8 use Drupal\Core\Form\FormStateInterface;
9
10 /**
11  * Implements hook_advagg_current_hooks_hash_array_alter().
12  */
13 function advagg_bundler_advagg_current_hooks_hash_array_alter(&$aggregate_settings) {
14   $aggregate_settings['variables']['advagg_bundler'] = \Drupal::config('advagg_bundler.settings')->get();
15 }
16
17 /**
18  * Implements hook_form_FORM_ID_alter().
19  */
20 function advagg_bundler_form_advagg_settings_alter(&$form, $form_state) {
21   if (advagg_bundler_enabled()) {
22     $form['global']['core_groups']['#disabled'] = TRUE;
23     $form['global']['core_groups']['#description'] = t('The bundler submodule disables core grouping logic.');
24     $form['global']['core_groups']['#states'] = [];
25     $form['global']['core_groups']['#default_value'] = FALSE;
26     array_unshift($form['#submit'], 'advagg_bundler_advagg_setting_form_submit');
27   }
28 }
29
30 /**
31  * Prevent the bundler config overrides from being saved into stored config.
32  */
33 function advagg_bundler_advagg_setting_form_submit(array &$form, FormStateInterface &$form_state) {
34   $form_state->setValue('core_groups', \Drupal::config('advagg.settings')->getOriginal('core_groups', FALSE));
35 }
36
37 /**
38  * Returns TRUE if the bundler will run.
39  *
40  * @param string $type
41  *   (optional) The type to check for - either 'css' or 'js'.
42  */
43 function advagg_bundler_enabled($type = NULL) {
44   $config = \Drupal::config('advagg_bundler.settings');
45   if (!$config->get('active')) {
46     return FALSE;
47   }
48   if ($type) {
49     return $config->get('max_' . $type);
50   }
51   if ($config->get('max_css') || $config->get('max_js')) {
52     return TRUE;
53   }
54 }