Hello. I have what is probably a somewhat basic question that I am struggling with. I am interested in overriding the provided stylesheets, parent.css and child.css. For the purposes of this question, assume that all Drupal performance options are off (no CSS optimization, etc.) and we are using a Zen-based theme with Firefox.

I followed this tutorial: http://drupal.org/node/263967 and copied parent.css and child.css to my theme directory, added them to my .info file, and cleared my cache. I made some changes to the css, however the modal boxes still come up with the default css.

I then checked it out in Firebug, and I see the ordering of the classes as follows:
/sites/all/modules/modalframe/css/parent.css?Y
/sites/all/themes/mytheme/parent.css

So even though it is included in my .info file, the modules css files are still winning the battle so all of my changes are eliminated. I initially thought that perhaps the argument was doing it, but the API seems to indicate that is just for caching: http://api.drupal.org/api/function/drupal_get_css/6

I'm not sure where to punt this - if it's a module or theme question so I thought I would start here. Thoughts are welcome.

CommentFileSizeAuthor
#3 modalframe.jpg166.98 KBrjbrown99

Comments

rjbrown99’s picture

Oh, and if it matters - this is not a subtheme and each successive retry on my part has included a clear of both the Drupal cache and the browser cache.

markus_petrux’s picture

Category: support » bug
Status: Active » Needs review

I was not aware of this feature in D6 theming layer. I have not created any theme for D6 yet. This probably affects other modules I have written. :(

hmm... I think I would have to rename to files so that they have a unique name. And this would avoid file name conflicts, and you would have only one CSS file.

Please, try this:

1) Rename css/parent.css to css/modalframe.parent.css
2) Rename css/child.css to css/modalframe.child.css
3) Apply the following mini patch to modalframe.module:

-  drupal_add_css($module_path .'/css/parent.css');
+  drupal_add_css($module_path .'/css/modalframe.parent.css');
-  drupal_add_css($module_path .'/css/child.css');
+  drupal_add_css($module_path .'/css/modalframe.child.css');

Other than that, if you can test this in firefox, the HTML tab in firebug allows you to see which stylesheets are applied to any DOM element.

rjbrown99’s picture

StatusFileSize
new166.98 KB

Thanks for the reply. I renamed as indicated, patched the module, cleared Drupal cache, and cleared the browser cache. I also then copied parent.css to modalframe.parent.css in my theme directory and called it via my .info file.

The new CSS files do come up via Firebug but unfortunately the module's theme file still 'wins' - see Firebug screenshot. This seems contrary to the handbook page explaining that when a .css file from a module is redefined in the main theme it wins and the local css file is loaded instead of the module's version.

The next thing I decided to do was to figure out if my theme is messing with the expected behavior somehow. I took the default Garland theme, edited garland.info to include a stylesheet with the same name (modalframe.parent.css), copied modalframe.parent.css into the Garland dir, cleared my theme cache, and switched to the Garland theme. The same thing happened - the modalframe module stylesheet still wins the battle over the theme's stylesheet with the same name.

Finally I wanted to see if the function would work at all, so I tried it with nodereference explorer's stylesheet. They include a sheet nodereference_explorer/css/explorer.tabs.css with their module. I copied explorer.tabs.css to the Garland directory, edited the .info file, cleared caches, reloaded the page, and now the theme version of explorer.tabs.css does win the battle and overrides the module's sheet.

Here's what they seem to be doing in that module:

nodereference_explorer_add_css('explorer.tabs');

and then...

/**
 * Add CSS style sheets
 * @param array $files
 */
function nodereference_explorer_add_css($files = array()) {
  // Convert file to an array if it's not one already, to compensate for
  // lazy developers. ;)
  if (!is_array($files))
    $files = array($files);

  $css_path = NODE_REFERENCE_EXPLORER_MODULE_PATH .'/css'; //from css subpath

  foreach ($files as $file)
    drupal_add_css($css_path . '/' . "$file.css");
}

Hopefully that is helpful. I may try to hack in a similar css loading function to modalframe and see what happens.

rjbrown99’s picture

Ok, very strange, but I changed modalframe to look like this:

  $module_path = drupal_get_path('module', 'modalframe');
  $css_path = $modulepath .'/css';
  drupal_add_css($css_path . '/' . "modalframe.parent.css");

... and now it works. The theme version overrides the module version of the stylesheet if there is a sheet with the same name. If I change it back to your code from #2 above, the behavior reverts back to the module winning the stylesheet battle.

I haven't the foggiest why one works and the other doesn't - I just followed the way the Nodereference Explorer module was doing it and now it works.

rjbrown99’s picture

Nope, it only 'works' because I screwed it up - forgot an underscore above. Removing modalframe.parent.css from my theme results in a window that has no css theming at all. Pfft. I fixed it up, but there is no change in behavior - module stylesheet still beats the theme stylesheet with the same name.

I tried it with the exact same code from Nodereference Explorer from #3 - change to modalframe_add_css('modalframe.parent'); with a call to this:

/**
* Add CSS style sheets
* @param array $files
*/
function modalframe_add_css($files = array()) {
  // Convert file to an array if it's not one already, to compensate for
  // lazy developers. ;)
  if (!is_array($files))
    $files = array($files);

  $module_path = drupal_get_path('module', 'modalframe');
  $css_path = $module_path .'/css'; //from css subpath

  foreach ($files as $file)
    drupal_add_css($css_path . '/' . "$file.css");
}

BZZZT, still no dice! The original stylesheet loads from the module and still overrides the theme's stylesheet. Firebug shows the same result as the above screenshot.

I'm starting to think I would have saved a lot of time had I just edited parent.css and child.css and been done with it :)

markus_petrux’s picture

Title: Theming question - overriding stylesheets » Use unique filename for CSS files to allow overriding stylesheets from theme
Status: Needs review » Fixed

Try adding the following to the .info file of your theme:

stylesheets[all][] = modalframe.parent.css

The file modalframe.parent.css should be placed in the main directory of your theme.

I have tested this with acquia_marina and worked like a charm. In the HTML source of the page you should only see this CSS file once, the one in your theme directory, which is the replacement of the one provided by the module itself. For example, using acquia_marina, I got this:

<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/darwin/darwin_workflow/css/admin_menu_widget.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/admin_menu/admin_menu.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/admin_menu/admin_menu.uid1.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/node/node.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/system/defaults.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/system/system.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/system/system-menus.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/user/user.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/poll/poll.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/cck/theme/content-module.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/ctools/css/ctools.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/date/date.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/date/date_popup/themes/datepicker.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/date/date_popup/themes/timeentry.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/extlink/extlink.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/filefield/filefield.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/fivestar/css/fivestar.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/fivestar/widgets/small/small.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/og/theme/og.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/panels/css/panels.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/sphinxsearch/sphinxsearch.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/calendar/calendar.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/misc/farbtastic/farbtastic.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/cck/modules/fieldgroup/fieldgroup.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/darwin/darwin_extensions/css/styles.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/active_tags/active_tags.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/noderelationships/css/node_form.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/imagefield/imagefield.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/themes/acquia_marina/style.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/themes/acquia_marina/icons.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/themes/acquia_marina/dblog.css?U" />

<link type="text/css" rel="stylesheet" media="all" href="/sites/all/themes/acquia_marina/modalframe.parent.css?U" />

<link type="text/css" rel="stylesheet" media="all" href="/sites/all/themes/acquia_marina/theme_settings/fixed.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/themes/acquia_marina/theme_settings/fonts_1.css?U" />

The file modalframe.parent.css provided by the module is not there.

I just committed the changes described in #2, and I hope this fixes the issue, which is that I was using a filename for CSS files too generic.

http://drupal.org/cvs?commit=263110

rjbrown99’s picture

Thanks Markus. I'm still having the same problem whereby the module's css sheet overtakes the sheet provided by the theme, even though it is properly specified. Here's a bit more info.

When the page is first loaded, and prior to opening any modal windows, my region has a few classes that look like this:

<style media="all" type="text/css">
@import "/modules/node/node.css";
@import "/modules/system/defaults.css";
@import "/modules/system/system.css";
@import "/modules/system/system-menus.css";
@import "/modules/user/user.css";
@import "/sites/all/modules/admin_menu/admin_menu.css";
(and so on - no modalframe.parent.css in here)
</style>
<style media="all" type="text/css">
@import "/sites/all/themes/mytheme/block-editing.css";
@import "/sites/all/themes/mytheme/wireframes.css";
@import "/sites/all/themes/mytheme/layout-fixed.css";
@import "/sites/all/themes/mytheme/mytheme.css";
@import "/sites/all/themes/mytheme/modalframe.parent.css";
</style>

Looks good - only the modalframe from the theme is loaded. None of this happens via
statements - it's all imported. I verified this in Firebug's CSS tab where the only file loaded and available to review is modalframe.parent.css from the theme. The other one from the module is not there at all.

Now the interesting part. When I click to engage the modalframe window (which in my case is a nodereference explorer window), I can see that my page changes and now has
statements inserted in the of the page below the other

and declarations at the very bottom of the section, like this:
<link href="/modules/node/node.css?O" media="all" rel="stylesheet" type="text/css"></link>
<link href="/modules/system/defaults.css?O" media="all" rel="stylesheet" type="text/css"></link>
<link href="/modules/system/system.css?O" media="all" rel="stylesheet" type="text/css"></link>
<link href="/modules/system/system-menus.css?O" media="all" rel="stylesheet" type="text/css"></link>
<link href="/modules/user/user.css?O" media="all" rel="stylesheet" type="text/css"></link>
<link href="/sites/all/modules/admin_menu/admin_menu.css?O" media="all" rel="stylesheet" type="text/css"></link>
(and so on)
<link href="/sites/all/modules/modalframe/css/modalframe.parent.css?O" media="all" rel="stylesheet" type="text/css">
... where the module's css sheet now comes into play. Since it was loaded after the theme's stylesheet above, it seems to win the battle and its classes are the ones that are used to display the window. That's how I end up with the file loaded twice. If I watch this behavior 'live' in Firebug, the statements are colored in yellow while they are appearing, so I am guessing some bit of Javascript somewhere is importing CSS classes when the window is opened. There only seem to be two possibilities - the modalframe javascript is doing it or the nodereference explorer javascript is doing it. Here's an interesting thing in the nodereference explorer.actions.js, near the top, Action for opening the dialog: http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/nodereference_explorer/js/explorer.actions.js?revision=1.2&view=markup
  //set the options according to the dialog api, built-in has dialog buttons
  if (settings['dialog_api'] == 'modalframe') {
  //prepare modalfram by loading js and css
  $.getJSON(settings['modalframe'], function(data, textStatus) {
    Drupal.nodereference_explorer.addCSS(data.css); //add css files
Perhaps that is what's going on? Your thoughts are welcome - I am starting to think this now might be an issue with nodereference explorer.
markus_petrux’s picture

It seems NRE is adding the module stylesheets via Drupal.settings, so it looks like a bug there.

Modal Frame API does not add stylesheets dynamically, so this is probably something else. I cannot really tell because I haven't used Node Reference Explorer (NRE). I just looked at it briefly a few weeks ago, to evaluate if it could solve a request I had, but I ended up coding Node Relationships module.

rjbrown99’s picture

Thanks Markus - I think that just about does it then. I appreciate the help/commit and I'll move on over to the NRE queue to report that one.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.