Closed (fixed)
Project:
Fork of CSS Embedded Images
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
17 Sep 2011 at 02:49 UTC
Updated:
13 Jan 2012 at 22:50 UTC
Jump to comment: Most recent file
Mike, how would you suggest I add the advagg_css_extra_alter() hook to the Fusion theme - for support of its CSS conditionals?
Currently, I have this: (fusion_core/template.php)
// Peter: Conditional CSS: + Updated for CDN to use file_create_url() instead of base_path()
// Add grid, color, ie6, ie7, ie8 & local stylesheets, including inherited & rtl versions
$grid_style = '/css/' . theme_get_setting('theme_grid');
$themes = fusion_core_theme_paths($theme_key);
// $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1); // Peter: no to this '' - it causes Query Strings to CDN
$style_categories = array(
// category => file basename
'setting' => $grid_style,
'ie6' => 'css/ie6-fixes',
'ie7' => 'css/ie7-fixes',
'ie8' => 'css/ie8-fixes',
'local' => 'css/local',
);
// Initialize.
$css_files = array();
foreach (array_keys($style_categories) as $category) {
$vars[$category . '_styles'] = '';
}
// Find all CSS files that should be added.
foreach ($themes as $name => $path) {
foreach ($style_categories as $category => $file_basename) {
// Check if a CSS file for this style category exists.
if (file_exists($path . $file_basename . '.css')) {
$css_files[$category] = $path . $file_basename . '.css';
}
// Check if a CSS file for this style category, but in RTL, exists.
if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && file_exists($path . $file_basename . '-rtl.css')) {
$css_files[$category] = $path . $file_basename . '-rtl.css';
}
}
}
$link_prefix = '<link type="text/css" rel="stylesheet" media="all" href="';
$link_suffix = '" />' . "\n";
// Add all found CSS files to their corresponding style categories.
foreach ($css_files as $category => $css_file) {
// Use the file_create_url() function to create file URLs when it's
// available, to add automatic support for CDN integration.
// This is also the way it will work in Drupal 7.
if (module_exists('cdn')) {
$vars[$category . '_styles'] .= $link_prefix . file_create_url($css_file) . $link_suffix;
}
else {
$vars[$category . '_styles'] .= $link_prefix . base_path() . $css_file . $link_suffix;
}
}
Thanks for any tips!
Advagg's advagg_css_extra_alter() hook API is not well documented!
The closest I can get to knowing advagg_css_extra_alter() is picking away at the advagg patched 'css_emimage' module!
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | css_embedded_images-do-not-alter-if-prefix-or-suffix-1282154-29.patch | 517 bytes | mikeytown2 |
| #10 | advagg-1282154-10.patch | 5 KB | mikeytown2 |
Comments
Comment #1
mikeytown2 commentedLooks like you can tell what type of conditional it will be based off of the filename, correct?
Then you add in the files by using drupal_add_css() or including it in the themes info file, and hook_advagg_css_extra_alter() will make it conditional. It was the only way I could think of making drupal_add_css work like this without hacking up core. If you can't tell what kind of prefix to use based off of the filename then using some sort of lookup is how to do it (see css_emimage).
Comment #2
Peter Bowey commentedMany thanks Mike,
The above code templates advagg's *hook()* method very well!
Great to get such a fast and helpful answer!
Comment #3
mikeytown2 commentedMarking this as fixed. Re-open if this is not the case.
Comment #4
Peter Bowey commentedMike, in using this method, via themes .inf, the style sheets remained static! No prefix /suffix occurred.
I tried using both the base theme; 'fusion_core' as well the sub-theme 'acquia_prosper'
I am missing something here.
Code in base template.php [fusion_core]
fusion_core.info:
Referring to your post http://drupal.org/node/1154732
Comment #5
mikeytown2 commenteddid you flush the caches?
Comment #6
Peter Bowey commentedRefer #5
Yes, full flush! Even changed the theme to another and then back to 'acquia_prosper'!
advagg 'Debug' shows that the 3 IE* conditional files are simply part of the aggregate 'bundle' -not seperate.
Comment #7
Peter Bowey commentedI note that the D7 version of 'fusion' theme uses this method:
But that's the new D7 'conditional' drupal_add_css()
Reference: http://drupal.org/node/1154732#comment-4457636
Comment #8
mikeytown2 commentedworking on a solution... need to pull the .css file out of the aggregate first & looks like you've found a bug! Working on a patch for this :)
Comment #9
Peter Bowey commentedMany thanks Mike!
This is part of work on client's D6 website - with a 'short' ETA.
By the way, the client loves the *new* site speed with 'CDN + Boost + Advagg'.
I appreciate your code and motivation!
Comment #10
mikeytown2 commentedTry this
With this patch that has just been applied to git.
Comment #11
Peter Bowey commentedMany thanks Mike,
will report on status shortly!
Adding code now...
Comment #12
mikeytown2 commentedThe JS side looks like it might take some clean-up to get it where I want it.
Comment #13
Peter Bowey commentedStill a issue Mike...
Seems that 'css_emimage' is doing stuff on the CSS conditionals:
Using advagg/info view shows this:
No CSS conditionals yet, other than those generated by 'css_emimage'
advagg's hook/theme 'info' shows:
Comment #14
Peter Bowey commentedI will try shifting the 2 above functions 'hook_advagg_css_*' to the 'child theme' -> acquia_prosper
via it's' template.php'
Comment #15
Peter Bowey commentedNope, the child theme 'acquia_prosper' does not use a 'preprocess' hook.
Reverting to using Paul Irish's / html5-boilerplate -> conditional CSS 'classes' in the html tag
Also, see -> http://drupal.org/project/zentropy
Comment #16
mikeytown2 commentedFirst step, are the conditional css files out of the aggregates and by them self? That is what hook_advagg_css_pre_alter() is for.
Comment #17
Peter Bowey commentedNo, the 'conditional css' files are bundled in the aggregate!
Comment #18
mikeytown2 commentedAdvAgg has very aggressive caching so be sure to flush after every change/test we are doing here. It was the only way to be faster then what core does and provide all of this functionality. I did get this to work locally, so it can be done.
Just for kicks run this, it will echo out in this hook. Make sure the hook is running.
Comment #19
Peter Bowey commentedThanks Mike,
I applied the above code, then 'dosed well' with full flushes, template change, reset advagg, and etc...
I can now conclude that both;
are not called in the 'fusion_core' template.php
The
gave no display or logs whatsoever?
Here is [part] of the given 'fusion_core' template.php
The fusion_core.info file has this:
I am 'dense and stupid'
but ready for Step '2'...
Comment #20
mikeytown2 commentedTime to try plan B. Change the hook names from "fusion_core" to "node"
Comment #21
Peter Bowey commentedOK will try that, thanks!
Comment #22
Peter Bowey commentedOK that shot out some values via print_r();
I disabled this once it was tested, as it is a live site -with real clients... :)
Comment #23
Peter Bowey commentedI notice from the above print_r() that the last /*/*.css is one long string?
If I expand and format the print_r() we have:
Comment #24
Peter Bowey commentedJust realized there was a 2nd 'echo' line in the debug code :)
So I removed both 'echo' lines and ran the show:
Notes: Interesting change of conditionals here; [if gte IE 8] - and why the 'query string'?
I have setup my Edgecast PULL CDN to return requests with 'query' strings back to the origin source...
Does this suggest that
function node_advagg_css_extra_alter(&$values)is not being called?Answer: No, I did some debug echo's and the three CSS files arrive within the node_advagg_css_extra_alter(),
and are selectively processed by '(strpos($filename, 'iex-fixes.css'). So the prefix + suffix are being ignored.
Conclusion: I hazard a 'guess' that css_emimage is over-riding this conditional processing, for it is the only 'hook' that offers
the incorrect '
<!--[if gte IE 8]><!-->'css_emimage.module
I am not sure [yet] how to deal with this $type 'problem'.
[Later] I made a simple change to the above css_emimage_advagg_css_extra_alter()
and now we have this result:
Thoughts; conditional CSS files are unlikely to have 'Embedded Images' as we are mostly dealing with CSS IE* issues...
Now it would be good to get rid of the 'query string' and have md5 / unique 'bundle' filename...
In advagg.module we have:
I use etags [generally] for such 'changes'. So for now, I have 'zapped' the advagg $query_string
Comment #25
mikeytown2 commentedOK, to go that route it will be a different work flow. hook_advagg_filenames_alter() will be the weapon of choice. If I get the time I'll give you a fully working example tomorrow, but in short you need to create a bundle for each conditional... the advantage is if you have multiple IE-x (x being 7, etc...) files you can then aggregate them into one. So in this case you will not use hook_advagg_css_pre_alter().
Here's a quick start from the bundler sub module; below is not production ready code.
Comment #26
Peter Bowey commentedMany thanks Mike!
Is that a real 'bug' with css_emimage_advagg_css_extra_alter() - per my tests above?
Some amazing 'potential' exists in advagg APIs!
Comment #27
mikeytown2 commentedIn regards to css_emimage; thats the problem when you only use a hook in one place, one finds bugs when the 2nd implementation of the API is in use. A quick fix for that below.
Comment #28
mikeytown2 commentedMoving this over here, so it can be fixed.
Comment #29
mikeytown2 commentedThis patch has been committed.
Comment #30.0
(not verified) commentednotes on css_emimage as guide