Hi,

The editablefields module uses ajax_load to deal with dynamic form injection to the DOM. It works well, however it doesn't seem to support Garland with custom colors. There's a support request in the editablefields issues queue that I believe is related to ajax_load: #359432: Editable fields change theme color on load with Views or on individual nodes

Looking at how Garland implements custom colors, it invokes a color.module function, _color_page_alter(), from its own phptemplate_preprocess_page() implementation to rebuild the CSS array of the page.

However, when modules such as editablefields send the response to ajax requests, theme('page') is not involved, so this particular processing made by Garland/color.module is not invoked, hence the custom colors od the site disappear when ajax_load processes the CSS array of the json response from the server.

Would it be possible to add something to ajax_load module to add support for this particular use of the Drupal CSS array?

CommentFileSizeAuthor
#9 ajax_load-361165-9.patch741 bytesmarkus_petrux

Comments

nedjo’s picture

Good question. It looks complex to address. I'd welcome ideas.

markus_petrux’s picture

I haven't tested this, but I think it might be a start.

In ajax_load.module, function ajax_data_get_data():

   $return['css'] = drupal_add_css();
+
+  // Hook into color.module
+  if (module_exists('color')) {
+    init_theme();
+    _color_page_alter($return);
+  }
+  
+
   return $return;
Anonymous’s picture

markus: Just tested your fix in Ajax Load 6.x-1.1. It worked for me, at least in the use cases I originally reported (#359432: Editable fields change theme color on load with Views or on individual nodes). Color shift no longer occurs at View or Node levels.

If you want to test other cases, let me know how I can help.

Thanks again--this makes two issues I've reported that you've solved!

ec’s picture

+1
@Markus, thanks for your patch, I can too confirm that it works fine and as espected with editable field and views with Garland custom theme.

rokr’s picture

I can confirm this patch works for theme 'Pixture Reloaded' as well. Thanks!

samhassell’s picture

patch also works for me using pixture_reloaded.

markus_petrux’s picture

Status: Active » Reviewed & tested by the community

Thanks for the feedback. I would say this is reviewed and tested.

@nedjo: please, let me know if you wish a formal patch or is it ok as in #2

nedjo’s picture

@markus_petrux: Thanks! I've assigned you CVS access. Please go ahead and apply this patch to HEAD. (There is no other branch yet.)

markus_petrux’s picture

Status: Reviewed & tested by the community » Fixed
StatusFileSize
new741 bytes

Sweet! Thanks for the confidence, nedjo. :-D

I have committed the fix, with a little comment in reference to color.module and Garland theme. Attached.

Now, I guess this will available in the next automatic snapshot. Not sure because this is HEAD.

Status: Fixed » Closed (fixed)

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

tm01xx’s picture

hi,

I'm using ajax_load module version 6.x-1.3 so it includes this patch already but my theme is still broken when using editablefield with views.

In my case, I'm using garland custom color theme as admin theme and another theme in front end. After the ajax_load, it changes the garland theme to another theme which causes break the admin page.

Please help.

tm01xx’s picture

From my understanding, seems it always loads the default theme which is front-end one?

tm01xx’s picture

Title: Add support for Garland with custom colors » Page broken when using 2 different themes
Version: 6.x-1.x-dev » 6.x-1.3
Category: feature » bug
Status: Closed (fixed) » Active

After some tests I could confirm that ajax_load module is not working properly when you have 2 themes (one for admin and another for front end). The issue is that it replaces admin theme (css files) by the front end ones causing the site broken.

Steps to re-produce:

1. Having 2 themes, i'm using garland for admin, my custom theme for front end.

2. Using Views with editablefield in admin theme. You could set a test path like this: admin/test so that your page will use admin theme.

3. Run the path. The page is broken. Check the css files then you will see all are from the front end theme, not admin theme.

btopro’s picture

having a similar issue when using spaces / context since that will load in different CSS based on context. Why is it even loading CSS for the fields? Shouldn't it all be on the page anyway?

Similarly, i'm noticing an issue that seems related with page JS loading that I don't want to load or loading multiple times which sets events incorrectly in some instances.

mrjeeves’s picture

i have also had this issue with color related modules, the patch is stable.

markus_petrux’s picture

Status: Active » Postponed (maintainer needs more info)

Still an issue with ajax_load 6.x-1.4?

markus_petrux’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

@tm01xx: If your issue is with Admin Theme, the solution could come from reviewing the paths where the Admin Theme should be enabled to include the paths used by Views Ajax.

@btopro: Probably the same problem. You may need to review the rules that define the contexts.

In short, the problem may come from something external to Ajax Load.

If suggestions don't help. Then I think it would be better to open a separate issues. This one has a patch that was included in Ajax Load 6.x-1.2. Thanks for your collaboration.

PS: Restoring original issue status, back to "closed (fixed)".

lort’s picture

Status: Closed (fixed) » Needs review

I had the same issue that came up when I installed editablefields and ajax_load.

ajax_load version used: 6.x-1.4

3 themes installed and enabled, and using 'sections' module to change theme based on path.

when I ajax_load is used by editablefields in a sections enabled theme, the default theme's css are loaded.

so I went through ajax_load.module and after commenting out this line of code, $data->css = $extra['css']; in ajax_load_ajax_data_alter(), everything came back to normal, without noticing anything going wrong in theme or functionality.

function ajax_load_ajax_data_alter(&$data) {
  $extra = ajax_data_get_data();
  $array = FALSE;
  // Detect whether the data being altered is an array.
  if (is_array($data)) {
    $data = (object) $data;
    $array = TRUE;
  }
  $data->scripts = $extra['scripts'];
  $data->css = $extra['css']; // <---------- comment out this line for a quick fix.
  if (!isset($data->__callbacks)) {
    $data->__callbacks = array();
  }
  // Set the AjaxLoad custom event as a callback.
  $data->__callbacks[] = 'Drupal.AjaxLoad.loadFiles';
  // Cast back to an array if necessary.
  if ($array) {
    $data = (array) $data;
  }
}

I did not investigate any further, as in how or why etc, cause i'm on a tight schedule.

Hope this helps.

vishun’s picture

Notice: Undefined index: logo in _color_page_alter() (line 114 of /var/www/modules/color/color.module).

There appears to still be an issue with 6.x-1.4 when the color module is in use with Garland (and probably other themes that use the color module) that causes a spammie watchdog notice. The _color_page_alter(&$vars) function normally receives a lot more $vars than ajax_load is providing. In particular it is missing the 'logo' index key which causes a notice on every (admin?) page load.

This can be easily fixed by defining something, anything, for the logo key. This may not be the exact proper fix but it does resolve the undefined index notice. For example, add $return['logo'] = null; to function ajax_data_get_data();

<?php
/**
 * Return an array of data representing the scripts and CSS files on a page.
 */
function ajax_data_get_data() {
  $return = array();
  $return['scripts'] = array();
  foreach (array('header', 'footer') as $scope) {
    $javascript = drupal_add_js(NULL, NULL, $scope);
    foreach ($javascript as $type => $data) {
      if (!$data) {
        unset($javascript[$type]);
      }
      elseif ($type == 'setting') {
        $javascript[$type] = call_user_func_array('array_merge_recursive', $data);
      }
    }
    $return['scripts'] = array_merge_recursive($return['scripts'], $javascript);
  }
  $return['css'] = drupal_add_css();
  $return['logo'] = null; // <-------- kinda hacky, but works

  // Allow the color.module alter the CSS array as if it was processed from
  // a regular page request. See phptemplate_preprocess_page() in garland.
  if (module_exists('color')) {
    init_theme();
    _color_page_alter($return);
  }

  // Deal with jQuery Update module, if exists.
  if (module_exists('jquery_update')) {
    ajax_load_jquery_update_preprocess($return);
  }

  return $return;
}
?>