Ok. This is going to be a little crazy, but hear me out.

I'd like it if there was a drupal_alter() on the data prior to saving the CSS in advagg_save_data(). This would allow for e.g. something like Color.module that could be used with SASS so that the site's colors could be customized from the website and then bundled up with the compiled SASS and pushed through AdvAgg. Sounds crazy, but it'd open up some interesting possibilities for sites that want website-level color control.

CommentFileSizeAuthor
#1 advagg-n2217381-1.patch1.26 KBDamienMcKenna
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna’s picture

Status: Active » Needs review
FileSize
1.26 KB

Here's the patch with the drupal_alter() line and documentation in advagg.api.php.

mikeytown2’s picture

What about hook_advagg_save_aggregate_alter()? I use it to gzip files as an example.


  $other_parameters = array($files, $type);

/**
 * Allow other modules to alter the contents and add new files to save (.gz).
 *
 * @param array $files_to_save
 *   array($uri => $contents)
 * @param array $aggregate_settings
 *   array of settings.
 * @param array $other_parameters
 *   array of containing $files & $type.
 *
 * @see advagg_save_aggregate()
 * @see advagg_advagg_save_aggregate_alter()
 */
function hook_advagg_save_aggregate_alter(&$files_to_save, $aggregate_settings, $other_parameters) {
...

Thinking I should alter the weight of advag_advagg_save_aggregate_alter so it runs last now that I see other use cases for this. This same hook is used here for S3 #2143913-9: Configure stream wrapper for storing aggregates

mikeytown2’s picture

The other alt for this use case is higher up hook_advagg_get_css_aggregate_contents_alter(). Given your example use case this is the hook I would use.

/**
 * Allow other modules to modify this aggregates contents.
 *
 * @param string $data
 *   Raw CSS data.
 * @param array $files
 *   List of files used to create this aggregate.
 * @param array $aggregate_settings
 *   An associative array of hooks and settings used.
 *
 * @see advagg_get_css_aggregate_contents()
 * @see advagg_css_compress_advagg_get_css_aggregate_contents_alter()
 */
function hook_advagg_get_css_aggregate_contents_alter(&$data, $files, $aggregate_settings) {
  if (empty($aggregate_settings['variables']['advagg_css_compressor'])) {
    return;
  }

  if ($aggregate_settings['variables']['advagg_css_compressor'] == 2) {
    advagg_css_compress_yui_cssmin($data);
  }
}
DamienMcKenna’s picture

Status: Needs review » Closed (works as designed)

Oh, hey, awesome. Yeah, these will work, thanks!

mikeytown2’s picture

Yep :)

If you want to go even higher, before the CSS is aggregated together hook_advagg_get_css_file_contents_alter() would be the ticket

/**
 * Allow other modules to modify this files contents.
 *
 * @param string $contents
 *   Raw file data.
 * @param string $file
 *   Filename
 * @param array $aggregate_settings
 *   An associative array of hooks and settings used.
 *
 * @see advagg_get_css_aggregate_contents()
 * @see advagg_css_compress_advagg_get_css_aggregate_contents_alter()
 */
function hook_advagg_get_css_file_contents_alter(&$contents, $file, $aggregate_settings) {