I noticed that the wrong theme function was being used to generate multigroup fieldsets when usign the 'Add more values' button. The markup being returned was generated by my site's default theme, though I was using an administration theme on node edit pages.

This patch adds a check in content_multigroup_add_more_js() , which switched to the admin theme if appropriate.

Instructions to recreate this bug:

  1. Create a content type and add a multigroup with fields.
  2. Go to admin/themes/admin and choose an admin theme that implements theme_fieldset(), check 'Use administration theme for content editing'.
  3. On the node creation form, press the 'Add more values' button at the bottom of the multigroup fieldset.
  4. Your admin theme's fieldset theme function is ignored, and its customizations to the fieldset markup are lost.

Comments

dboulet’s picture

StatusFileSize
new1.11 KB
dan3h’s picture

I am having a similar problem. I have date-field that accepts multiple values. Drupal's date field widgets have 4 fields in them: from-date, from-time, to-date, to-time; and I used a #pre_render hook to set one of them to hidden. This works just like I want it to.

The problem arises when you click the "Add another item" button; the AHAH call which adds in the extra fieldset also reformats all the previous values to the original formatting. That is, the fields which I had hidden so carefully all become visible again.

Here is the code I am using to hide the fields:

function mymodule_form_alter(&$form, $form_state, $form_id) {      
  
  if ($form_id == 'course_node_form') {

    // Drupal's Date-range field has a from date/time and a to date/time.  
    //   We just want 1 date and 2 times, so we hide the to-date portion.

    $form['field_date']['#pre_render'] = array('_course_form_hide_todate_field');
    break;
  }
}
    

function _course_form_hide_todate_field(&$element) {
  foreach($element as $key => $date_instance) {
    if (is_numeric($key)) {
      $element[$key]['value2']['date']['#type'] = 'hidden';
    }
  }
  return $element;
}

Dan

dboulet’s picture

@dan3h, did you try my patch? Did it fix your problem?

dboulet’s picture

Still experiencing this issue, any chance of getting this patch reviewed?

karens’s picture

Status: Needs review » Fixed

@dan3h, that is a different issue. It's better not to confuse things.

I can't replicate any problem. If I set an admin theme, that is the theme that is used for both the original form and any new elements added by AHAH. If you're seeing behavior like this, it is likely something specific to the way you have things set up. No one else is having or ever has reported this problem.

If this is broken for multigroups, it would also be broken for everything else that uses AHAH, the field add more button, the Poll module add more button, etc.

dboulet’s picture

Status: Fixed » Needs review

Thanks for the feedback KarenS.

I am actually able to reproduce this quite easily. The reason that this is hard to spot is that most themes will return very similar markup for fieldsets.

Try this:

  1. From a new installation of D6, enable the content multigroup module
  2. Add a multigroup to the Page content type.
  3. Change the admin theme to anything but Garland, "Marvin" for example, and check "Use administration theme for content editing"
  4. Add this code to Garland's template.php:
    function garland_fieldset($element) {
      return 'foo';
    }
    
  5. Try adding a new page and hit the 'Add more values' button under the multigroup, the fieldset is replaced by 'foo'

This should not happen, the fieldset being loaded through AHAH is being rendered using the wrong theme.

karens’s picture

Again, this works the same everywhere that AHAH is used, including the add more button for fields and the Poll module questions. I don't see how this can only be a multigroup issue, and it's not clear to me why multigroup would need this bit of code but nothing else would.

dboulet’s picture

You're right KarenS, I tested the field add more button, and looks like the wrong theme is used in that case as well. So, like you said, this works the same everywhere that AHAH is used—but doesn't mean that it's not a bug.

karens’s picture

Component: content_multigroup.module » General
Status: Needs review » Needs work

I've never tried switching themes in a javascript callback. Might be the right thing to do, just don't know for sure how to handle it. And if we're going to do it it has to be done everywhere, not just in multigroup.

dboulet’s picture

Title: Multigroup AHAH function doesn't respect admin theme » CCK AHAH functions don't respect admin theme

Thanks KarenS, I'll get a new patch in for review.

dboulet’s picture

Status: Needs work » Needs review
StatusFileSize
new2.09 KB

I searched through the module to try to find all AHAH callbacks for node forms, and only found 2: the one used for the 'Add another item' button for fields, and the other for the 'Add more values' button for multigroups.

I've added a check in both of those callback functions that switches the theme if the admin theme is set to be used for content editing. My logic is that those callbacks will only be used on node forms, and should therefor respect the "Use administration theme for content editing" setting.

R-H’s picture

StatusFileSize
new75.11 KB
new64.62 KB
new39.09 KB

I'm having a weird bug and I'm guessing that it might be best logged here.

With a multigroup if I have a text input field in that group and Click the "Add More Values" button the width of that text input increases. It only happens on the 1st click of the the "Add More Values" button. On the 2nd click the inputs are the same new wider width. Text areas do not scale in width on click of the add more values button.

I have the Rubik theme installed and am using it to add new content.

See attached screen shots.

dboulet’s picture

Hi Ryan Hanau, I'm not sure if that is the same bug but maybe try the patch in #11 to see if it solves the problem.

hhopkins’s picture

For those that are comfortable writing custom modules and do not want to modify the CCK code, here is what I did fix the issue.

Adding the code from #11 using hook_init() allowed me to check the arg parameters and set the custom theme. One caveat is to make sure your custom module is called prior to any other modules that call theme functions in hook_init(). In our case another module was executing a theme function prior to our module and so the theme was being set before we could check to apply the custom admin theme. Here's the modified code:

/**
 * Implementation of hook_init().
 *
 * Make sure the admin theme is applied to the content_multigroup js_add_more callbacks.
 */
function module_name_init() {
  // Switch to administration theme if it is set to be used for content editing.
  if (arg(0) == 'content_multigroup' && arg(1) == 'js_add_more') {
    if (variable_get('node_admin_theme', 0) && variable_get('admin_theme', '0')) {
      global $custom_theme;
      $custom_theme = variable_get('admin_theme', '0');
    }
  }
}

Credit goes to dboulet for the original idea.