advagg_mod.module

  1. nittany7 modules/contrib/advagg/advagg_mod/advagg_mod.module
  2. cis7 modules/contrib/advagg/advagg_mod/advagg_mod.module
  3. mooc7 modules/contrib/advagg/advagg_mod/advagg_mod.module

Advanced aggregation modifier module.

Functions

Namesort descending Description
advagg_mod_advagg_get_root_files_dir_alter Implements hook_advagg_get_root_files_dir_alter().
advagg_mod_advagg_modify_js_pre_render_alter Implements hook_advagg_modify_js_pre_render_alter().
advagg_mod_css_alter Implements hook_css_alter().
advagg_mod_init Implement hook_init().
advagg_mod_inline_css Transforms all CSS files into inline CSS.
advagg_mod_inline_js Transforms all JS files into inline JS.
advagg_mod_inline_page Returns TRUE if this page should have inline CSS/JS.
advagg_mod_js_alter Implements hook_js_alter().
advagg_mod_js_contains_jquery_drupal See if JavaScript file contains drupal and/or jquery.
advagg_mod_magic Implements hook_magic().
advagg_mod_magic_form_validate Form validation handler. Disable certian magic settings before being saved.
advagg_mod_match_path Transforms all CSS files into inline CSS.
advagg_mod_menu Implement hook_menu().
advagg_remove_js_if_not_used Remove JS if not in use on current page.

Constants

Namesort descending Description
ADVAGG_MOD_CSS_PREPROCESS Default value to turn on preprocessing for all CSS files.
ADVAGG_MOD_JS_ASYNC_SHIM Default value to add use the async script shim for script tags.
ADVAGG_MOD_JS_DEFER Default value to add the defer tag to all script tags.
ADVAGG_MOD_JS_FOOTER Default value to move all JS to the footer.
ADVAGG_MOD_JS_PREPROCESS Default value to turn on preprocessing for all JavaScript files.
ADVAGG_MOD_JS_REMOVE_UNUSED Default value to remove JavaScript if none was added on the page.

File

modules/contrib/advagg/advagg_mod/advagg_mod.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Advanced aggregation modifier module.
  5. */
  6. // Define default variables.
  7. /**
  8. * Default value to move all JS to the footer.
  9. */
  10. define('ADVAGG_MOD_JS_FOOTER', 0);
  11. /**
  12. * Default value to turn on preprocessing for all JavaScript files.
  13. */
  14. define('ADVAGG_MOD_JS_PREPROCESS', FALSE);
  15. /**
  16. * Default value to add the defer tag to all script tags.
  17. */
  18. define('ADVAGG_MOD_JS_DEFER', FALSE);
  19. /**
  20. * Default value to add use the async script shim for script tags.
  21. */
  22. define('ADVAGG_MOD_JS_ASYNC_SHIM', TRUE);
  23. /**
  24. * Default value to turn on preprocessing for all CSS files.
  25. */
  26. define('ADVAGG_MOD_CSS_PREPROCESS', FALSE);
  27. /**
  28. * Default value to remove JavaScript if none was added on the page.
  29. */
  30. define('ADVAGG_MOD_JS_REMOVE_UNUSED', FALSE);
  31. // Core hook implementations.
  32. /**
  33. * Implement hook_init().
  34. */
  35. function advagg_mod_init() {
  36. // Return if unified_multisite_dir is not set.
  37. $dir = rtrim(variable_get('advagg_mod_unified_multisite_dir', ''), '/');
  38. if (empty($dir) || !file_exists($dir) || !is_dir($dir)){
  39. return;
  40. }
  41. $counter_filename = $dir . '/' . ADVAGG_SPACE . 'advagg_global_counter';
  42. $local_counter = advagg_get_global_counter();
  43. if (!file_exists($counter_filename)) {
  44. module_load_include('inc', 'advagg', 'advagg.missing');
  45. advagg_save_data($counter_filename, $local_counter);
  46. }
  47. else {
  48. $shared_counter = (int) file_get_contents($counter_filename);
  49. if ($shared_counter == $local_counter) {
  50. // Counters are the same, return.
  51. return;
  52. }
  53. elseif ($shared_counter < $local_counter) {
  54. // Local counter is higher, update saved file and return.
  55. module_load_include('inc', 'advagg', 'advagg.missing');
  56. advagg_save_data($counter_filename, $local_counter, TRUE);
  57. return;
  58. }
  59. elseif ($shared_counter > $local_counter) {
  60. // Shared counter is higher, update local copy and return.
  61. variable_set('advagg_global_counter', $shared_counter);
  62. return;
  63. }
  64. }
  65. }
  66. /**
  67. * Implement hook_menu().
  68. */
  69. function advagg_mod_menu() {
  70. $items = array();
  71. $file_path = drupal_get_path('module', 'advagg_mod');
  72. $config_path = advagg_admin_config_root_path();
  73. $items[$config_path . '/advagg/mod'] = array(
  74. 'title' => 'Modifications',
  75. 'description' => 'Turn on or off various mods for CSS/JS.',
  76. 'page callback' => 'drupal_get_form',
  77. 'page arguments' => array('advagg_mod_admin_settings_form'),
  78. 'type' => MENU_LOCAL_TASK,
  79. 'access arguments' => array('administer site configuration'),
  80. 'file path' => $file_path,
  81. 'file' => 'advagg_mod.admin.inc',
  82. 'weight' => 10,
  83. );
  84. return $items;
  85. }
  86. /**
  87. * Implements hook_js_alter().
  88. */
  89. function advagg_mod_js_alter(&$js) {
  90. if (module_exists('advagg') && !advagg_enabled()) {
  91. return;
  92. }
  93. // Only add JS if it's actually needed.
  94. if (variable_get('advagg_mod_js_remove_unused', ADVAGG_MOD_JS_REMOVE_UNUSED)) {
  95. advagg_remove_js_if_not_used($js);
  96. }
  97. // Move all JS to the footer.
  98. $move_js_to_footer = variable_get('advagg_mod_js_footer', ADVAGG_MOD_JS_FOOTER);
  99. if (!empty($move_js_to_footer)) {
  100. foreach ($js as $name => &$values) {
  101. if ($move_js_to_footer == 1 && $values['group'] <= JS_LIBRARY) {
  102. continue;
  103. }
  104. // If JS is not in the header increase group by 1000.
  105. if ($values['scope'] != 'header') {
  106. $values['group'] += 1000;
  107. }
  108. // If JS is already in the footer increase group by 1000.
  109. if ($values['scope'] == 'footer') {
  110. $values['group'] += 1000;
  111. }
  112. $values['scope'] = 'footer';
  113. }
  114. }
  115. // Do not use preprocessing if JS is inlined.
  116. // Do not use defer if JS is inlined.
  117. if (advagg_mod_inline_page()) {
  118. advagg_mod_inline_js($js);
  119. return;
  120. }
  121. // Force all JS to be preprocessed.
  122. if (variable_get('advagg_mod_js_preprocess', ADVAGG_MOD_JS_PREPROCESS)) {
  123. foreach ($js as $name => &$values) {
  124. $values['preprocess'] = TRUE;
  125. }
  126. }
  127. // Add the defer tag to all JS.
  128. if (variable_get('advagg_mod_js_defer', ADVAGG_MOD_JS_DEFER)) {
  129. foreach ($js as $name => &$values) {
  130. // Everything is defer.
  131. $values['defer'] = TRUE;
  132. if (strpos($name, 'jquery.js') !== FALSE || strpos($name, 'jquery.min.js') !== FALSE ) {
  133. // Do not defer the loading of jquery.js
  134. $values['defer'] = FALSE;
  135. // jquery_update fallback.
  136. if (module_exists('jquery_update')) {
  137. $values['onload'] = "if (typeof window.init_drupal_jquery_update_fallback === 'function') {init_drupal_jquery_update_fallback();}";
  138. }
  139. }
  140. if (strpos($name, 'jquery-ui.js') !== FALSE || strpos($name, 'jquery-ui.min.js') !== FALSE ) {
  141. // Do not defer the loading of jquery-ui.js
  142. $values['defer'] = FALSE;
  143. // jquery_update fallback.
  144. if (module_exists('jquery_update')) {
  145. $values['onload'] = "if (typeof window.init_drupal_jquery_ui_update_fallback === 'function') {init_drupal_jquery_ui_update_fallback();}";
  146. }
  147. }
  148. // Drupal settings.
  149. if ($name == 'misc/drupal.js') {
  150. $values['onload'] = "if (typeof window.init_drupal_core_settings === 'function') {init_drupal_core_settings();}";
  151. }
  152. }
  153. }
  154. }
  155. /**
  156. * Implements hook_css_alter().
  157. */
  158. function advagg_mod_css_alter(&$css) {
  159. if (module_exists('advagg') && !advagg_enabled()) {
  160. return;
  161. }
  162. // Do not use preprocessing if CSS is inlined.
  163. if (advagg_mod_inline_page()) {
  164. advagg_mod_inline_css($css);
  165. return;
  166. }
  167. // Force all CSS to be preprocessed.
  168. if (variable_get('advagg_mod_css_preprocess', ADVAGG_MOD_CSS_PREPROCESS)) {
  169. foreach ($css as $name => &$values) {
  170. $values['preprocess'] = TRUE;
  171. }
  172. }
  173. }
  174. // AdvAgg hook implementations.
  175. /**
  176. * Implements hook_advagg_modify_js_pre_render_alter().
  177. */
  178. function advagg_mod_advagg_modify_js_pre_render_alter(&$children, &$elements) {
  179. if (module_exists('advagg') && !advagg_enabled()) {
  180. return;
  181. }
  182. // Do not use defer/async shim if JS is inlined.
  183. if (advagg_mod_inline_page()) {
  184. return;
  185. }
  186. if (variable_get('advagg_mod_js_defer', ADVAGG_MOD_JS_DEFER)) {
  187. foreach ($children as &$values) {
  188. $values['#attributes']['defer'] = TRUE;
  189. if (empty($values['#value'])) {
  190. continue;
  191. }
  192. // Workaround bug with onload and jquery update.
  193. if (!empty($values['#attributes']['onload'])) {
  194. unset($values['#attributes']['onload']);
  195. }
  196. // Core
  197. if (strpos($values['#value'], 'jQuery.extend(Drupal.settings') !== FALSE) {
  198. $values['#value'] = 'function init_drupal_core_settings() {' . $values['#value'] . '}';
  199. }
  200. // jQuery Update
  201. if (strpos($values['#value'], 'window.jQuery') !== FALSE) {
  202. $values['#value'] = 'function init_drupal_jquery_update_fallback() {' . $values['#value'] . '}';
  203. }
  204. if (strpos($values['#value'], 'window.jQuery.ui') !== FALSE) {
  205. $values['#value'] = 'function init_drupal_jquery_ui_update_fallback() {' . $values['#value'] . '}';
  206. }
  207. }
  208. }
  209. if (variable_get('advagg_mod_js_async_shim', ADVAGG_MOD_JS_ASYNC_SHIM)) {
  210. foreach ($children as &$values) {
  211. if (isset($values['#attributes']) && isset($values['#attributes']['async']) && $values['#attributes']['async'] == 'async') {
  212. $source = url($values['#attributes']['src']);
  213. $values['#value'] = "(function() {
  214. var s = document.createElement('script');
  215. s.type = 'text/javascript';
  216. s.async = true;
  217. s.src = '$source';
  218. var d = document.getElementsByTagName('script')[0];
  219. d.parentNode.insertBefore(s, d);
  220. })();";
  221. unset($values['#attributes']['async']);
  222. unset($values['#attributes']['src']);
  223. }
  224. }
  225. }
  226. }
  227. /**
  228. * Implements hook_advagg_get_root_files_dir_alter().
  229. */
  230. function advagg_mod_advagg_get_root_files_dir_alter(&$css_paths, &$js_paths) {
  231. $dir = rtrim(variable_get('advagg_mod_unified_multisite_dir', ''), '/');
  232. if (empty($dir) || !file_exists($dir) || !is_dir($dir)) {
  233. return;
  234. }
  235. // Change directory.
  236. $css_paths[0] = $dir . '/advagg_css';
  237. $js_paths[0] = $dir . '/advagg_js';
  238. file_prepare_directory($css_paths[0], FILE_CREATE_DIRECTORY);
  239. file_prepare_directory($js_paths[0], FILE_CREATE_DIRECTORY);
  240. // Set the URI of the directory.
  241. $css_paths[1] = parse_url(file_create_url($css_paths[0]));
  242. $css_paths[1] = ltrim($css_paths[1]['path'], $GLOBALS['base_path']);
  243. $js_paths[1] = parse_url(file_create_url($js_paths[0]));
  244. $js_paths[1] = ltrim($js_paths[1]['path'], $GLOBALS['base_path']);
  245. }
  246. // Helper Functions.
  247. /**
  248. * Returns TRUE if this page should have inline CSS/JS.
  249. */
  250. function advagg_mod_inline_page() {
  251. $visibility = variable_get('advagg_mod_inline_visibility', BLOCK_VISIBILITY_LISTED);
  252. $pages = variable_get('advagg_mod_inline_pages', '');
  253. return advagg_mod_match_path($pages, $visibility);
  254. }
  255. /**
  256. * Transforms all JS files into inline JS.
  257. *
  258. * @param $js
  259. * JS array.
  260. */
  261. function advagg_mod_inline_js(&$js) {
  262. $aggregate_settings = advagg_current_hooks_hash_array();
  263. foreach ($js as $name => &$values) {
  264. // Only process files.
  265. if ($values['type'] != 'file') {
  266. continue;
  267. }
  268. $filename = $values['data'];
  269. if (file_exists($filename)) {
  270. $contents = file_get_contents($filename);
  271. }
  272. // Allow other modules to modify this files contents.
  273. // Call hook_advagg_get_js_file_contents_alter().
  274. drupal_alter('advagg_get_js_file_contents', $contents, $filename, $aggregate_settings);
  275. $values['data'] = $contents;
  276. $values['type'] = 'inline';
  277. }
  278. }
  279. /**
  280. * Transforms all CSS files into inline CSS.
  281. *
  282. * @param $css
  283. * CSS array.
  284. *
  285. * @see advagg_get_css_aggregate_contents()
  286. * @see drupal_build_css_cache()
  287. */
  288. function advagg_mod_inline_css(&$css) {
  289. $aggregate_settings = advagg_current_hooks_hash_array();
  290. $optimize = TRUE;
  291. module_load_include('inc', 'advagg', 'advagg');
  292. foreach ($css as $name => &$values) {
  293. // Only process files.
  294. if ($values['type'] != 'file') {
  295. continue;
  296. }
  297. $file = $values['data'];
  298. if (file_exists($file)) {
  299. $contents = advagg_load_css_stylesheet($file, $optimize, $aggregate_settings);
  300. // Allow other modules to modify this files contents.
  301. // Call hook_advagg_get_css_file_contents_alter().
  302. drupal_alter('advagg_get_css_file_contents', $contents, $file, $aggregate_settings);
  303. // Per the W3C specification at http://www.w3.org/TR/REC-CSS2/cascade.html#at-import,
  304. // @import rules must proceed any other style, so we move those to the top.
  305. $regexp = '/@import[^;]+;/i';
  306. preg_match_all($regexp, $contents, $matches);
  307. $contents = preg_replace($regexp, '', $contents);
  308. $contents = implode('', $matches[0]) . $contents;
  309. $values['data'] = $contents;
  310. $values['type'] = 'inline';
  311. }
  312. }
  313. }
  314. /**
  315. * Transforms all CSS files into inline CSS.
  316. *
  317. * @param $pages
  318. * string from the advagg_mod_inline_pages variable.
  319. * @param $visibility
  320. * visibility setting from the advagg_mod_inline_visibility variable.
  321. *
  322. * @see block_block_list_alter()
  323. */
  324. function advagg_mod_match_path($pages, $visibility) {
  325. // Limited visibility blocks must list at least one page.
  326. if ($visibility == BLOCK_VISIBILITY_LISTED && empty($pages)) {
  327. $page_match = FALSE;
  328. }
  329. elseif ($pages) {
  330. // Match path if necessary.
  331. // Convert path to lowercase. This allows comparison of the same path
  332. // with different case. Ex: /Page, /page, /PAGE.
  333. $pages = drupal_strtolower($pages);
  334. if ($visibility < BLOCK_VISIBILITY_PHP) {
  335. // Convert the Drupal path to lowercase
  336. $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
  337. // Compare the lowercase internal and lowercase path alias (if any).
  338. $page_match = drupal_match_path($path, $pages);
  339. if ($path != $_GET['q']) {
  340. $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
  341. }
  342. // When $visibility has a value of 0 (BLOCK_VISIBILITY_NOTLISTED),
  343. // the block is displayed on all pages except those listed in $pages.
  344. // When set to 1 (BLOCK_VISIBILITY_LISTED), it is displayed only on those
  345. // pages listed in $block->pages.
  346. $page_match = !($visibility xor $page_match);
  347. }
  348. elseif (module_exists('php')) {
  349. $page_match = php_eval($pages);
  350. }
  351. else {
  352. $page_match = FALSE;
  353. }
  354. }
  355. else {
  356. $page_match = TRUE;
  357. }
  358. return $page_match;
  359. }
  360. /**
  361. * See if JavaScript file contains drupal and/or jquery.
  362. *
  363. * @param $filename
  364. * filename or full URL.
  365. * @param $type
  366. * file or external
  367. *
  368. * @see block_block_list_alter()
  369. */
  370. function advagg_mod_js_contains_jquery_drupal($filename, $type) {
  371. module_load_include('inc', 'advagg', 'advagg');
  372. $info = advagg_get_info_on_file($filename);
  373. if (empty($info['advagg_mod']['contents'])) {
  374. if ($type == 'file') {
  375. $contents = file_get_contents($filename);
  376. }
  377. if ($type == 'external') {
  378. $result = drupal_http_request($filename);
  379. if (($result->code == 200 || (isset($result->redirect_code) && $result->redirect_code == 200)) && !empty($result->data)) {
  380. $contents = $result->data;
  381. }
  382. }
  383. if (!empty($contents) && stripos($contents, 'drupal.') !== FALSE) {
  384. $info['advagg_mod']['contents']['drupal'] = TRUE;
  385. if (stripos($contents, 'drupal.settings.') !== FALSE) {
  386. $info['advagg_mod']['contents']['drupal.settings'] = TRUE;
  387. }
  388. else {
  389. $info['advagg_mod']['contents']['drupal.settings'] = FALSE;
  390. }
  391. if (stripos($contents, 'drupal.behaviors.') !== FALSE) {
  392. $info['advagg_mod']['contents']['drupal.behaviors'] = TRUE;
  393. }
  394. else {
  395. $info['advagg_mod']['contents']['drupal.behaviors'] = FALSE;
  396. }
  397. }
  398. else {
  399. $info['advagg_mod']['contents']['drupal'] = FALSE;
  400. $info['advagg_mod']['contents']['drupal.settings'] = FALSE;
  401. $info['advagg_mod']['contents']['drupal.behaviors'] = FALSE;
  402. }
  403. if (!empty($contents) && stripos($contents, 'jquery') !== FALSE) {
  404. $info['advagg_mod']['contents']['jquery'] = TRUE;
  405. }
  406. else {
  407. $info['advagg_mod']['contents']['jquery'] = FALSE;
  408. }
  409. // Cache info.
  410. $filename_hashes = &drupal_static('advagg_get_info_on_file');
  411. $cache_id = 'advagg:file:' . $info['filename_hash'];
  412. // Save results.
  413. $filename_hashes[$cache_id] = $info;
  414. cache_set($cache_id, $info, 'cache_advagg_info', CACHE_PERMANENT);
  415. }
  416. return array($info['advagg_mod']['contents']['drupal'], $info['advagg_mod']['contents']['jquery']);
  417. }
  418. /**
  419. * Remove JS if not in use on current page.
  420. *
  421. * @param $js
  422. * JS array.
  423. */
  424. function advagg_remove_js_if_not_used(&$js) {
  425. // Do not run the following code if drupal_add_js_page_defaults exists.
  426. if (function_exists('drupal_add_js_page_defaults')) {
  427. return;
  428. }
  429. $files_skiplist = array(
  430. 'drupal.js',
  431. 'jquery.js',
  432. 'jquery.min.js',
  433. 'jquery.once.js',
  434. );
  435. $inline_skiplist = array(
  436. '/jquery_update/replace/jquery/1.5/jquery.min.js',
  437. 'var $L = $LAB.setGlobalDefaults',
  438. );
  439. $include_jquery = FALSE;
  440. $include_drupal = FALSE;
  441. // Look at each JavaScript entry.
  442. foreach ($js as $name => &$values) {
  443. if ($values['type'] == 'file' || $values['type'] == 'external') {
  444. $skip = FALSE;
  445. foreach ($files_skiplist as $skip_name) {
  446. if (substr_compare($name, $skip_name, -strlen($skip_name), strlen($skip_name)) === 0) {
  447. $skip = TRUE;
  448. break;
  449. }
  450. }
  451. if (!$skip) {
  452. list($drupal, $jquery) = advagg_mod_js_contains_jquery_drupal($name, $values['type']);
  453. if ($drupal) {
  454. $include_jquery = TRUE;
  455. $include_drupal = TRUE;
  456. }
  457. elseif ($jquery) {
  458. $include_jquery = TRUE;
  459. }
  460. }
  461. }
  462. if ($values['type'] == 'inline') {
  463. $skip = FALSE;
  464. foreach ($inline_skiplist as $skip_string) {
  465. if (stripos($values['data'], $skip_string) !== FALSE) {
  466. $skip = TRUE;
  467. break;
  468. }
  469. }
  470. if (!$skip) {
  471. $include_jquery = TRUE;
  472. $include_drupal = TRUE;
  473. }
  474. }
  475. }
  476. // Kill only drupal JavaScript.
  477. if (!$include_drupal) {
  478. unset($js['settings']);
  479. foreach ($js as $name => &$values) {
  480. $drupal = 'drupal.js';
  481. if (substr_compare($name, $drupal, -strlen($drupal), strlen($drupal)) === 0) {
  482. unset($js[$name]);
  483. }
  484. }
  485. // Kill all default JavaScript.
  486. if (!$include_jquery) {
  487. foreach ($js as $name => &$values) {
  488. if ($values['type'] == 'file' || $values['type'] == 'external') {
  489. foreach ($files_skiplist as $skip_name) {
  490. if (substr_compare($name, $skip_name, -strlen($skip_name), strlen($skip_name)) === 0) {
  491. unset($js[$name]);
  492. }
  493. }
  494. }
  495. elseif ($values['type'] == 'inline') {
  496. foreach ($inline_skiplist as $skip_string) {
  497. if (stripos($values['data'], $skip_string) !== FALSE) {
  498. unset($js[$name]);
  499. }
  500. }
  501. }
  502. }
  503. }
  504. }
  505. }
  506. /**
  507. * Implements hook_magic().
  508. *
  509. * @param array $magic_settings
  510. * The renderable form array of the magic module theme settings. READ ONLY
  511. * @param string $theme
  512. * The theme that the settings will be editing.
  513. *
  514. * @return
  515. * The array of settings within the magic module theme page. Must not contain
  516. * anything from the $magic_settings array.
  517. */
  518. function advagg_mod_magic($magic_settings, $theme) {
  519. $settings = array();
  520. // If possible disable access and set defult to false.
  521. if (!isset($magic_settings['css']['magic_embedded_mqs']['#access'])) {
  522. $settings['css']['magic_embedded_mqs']['#access'] = FALSE;
  523. }
  524. if (!isset($magic_settings['css']['magic_embedded_mqs']['#default_value'])) {
  525. $settings['css']['magic_embedded_mqs']['#default_value'] = FALSE;
  526. }
  527. if (!isset($magic_settings['js']['magic_footer_js']['#access'])) {
  528. $settings['js']['magic_footer_js']['#access'] = FALSE;
  529. }
  530. if (!isset($magic_settings['js']['magic_footer_js']['#default_value'])) {
  531. $settings['js']['magic_footer_js']['#default_value'] = FALSE;
  532. }
  533. if (!isset($magic_settings['js']['magic_library_head']['#access'])) {
  534. $settings['js']['magic_library_head']['#access'] = FALSE;
  535. }
  536. if (!isset($magic_settings['js']['magic_library_head']['#default_value'])) {
  537. $settings['js']['magic_library_head']['#default_value'] = FALSE;
  538. }
  539. if (!isset($magic_settings['js']['magic_experimental_js']['#access'])) {
  540. $settings['js']['magic_experimental_js']['#access'] = FALSE;
  541. }
  542. if (!isset($magic_settings['js']['magic_experimental_js']['#default_value'])) {
  543. $settings['js']['magic_experimental_js']['#default_value'] = FALSE;
  544. }
  545. // Add in our own validate function so we can preprocess variables before
  546. // they are saved.
  547. $settings['#validate'] = array('advagg_mod_magic_form_validate');
  548. return $settings;
  549. }
  550. /**
  551. * Form validation handler. Disable certian magic settings before being saved.
  552. */
  553. function advagg_mod_magic_form_validate($form, &$form_state) {
  554. // Disable magic functionality if it is a duplicate of AdvAgg.
  555. $form_state['values']['magic_embedded_mqs'] = 0;
  556. $form_state['values']['magic_footer_js'] = 0;
  557. $form_state['values']['magic_library_head'] = 0;
  558. $form_state['values']['magic_experimental_js'] = 0;
  559. }