Line 104, select_or_other.module:

  if ($element['#select_type'] == 'checkboxes') {
    $element['select']['#process'] = array('select_or_other_expand_checkboxes');
  }

This kills all process functions defined by hook_elemens() from other modules. I have this:

function multicolumncheckboxesradios_elements() {
  return array(
    'checkboxes' => array(
      '#multicolumn' => FALSE,
      '#process' => array('multicolumncheckboxesradios_element_process'),
    ),

}

but because of line 104, my process function is no longer called. Should remove line 104 and do something like this:

function select_or_other_elements() {
  return array(
    'checkboxes' => array(
      '#multicolumn' => FALSE,
      '#process' => array('select_or_other_expand_checkboxes'),
    ),
}

function select_or_other_expand_checkboxes($element) {
  if ($element IS CREATED BY SELECT_OR_OTHER) {
    foreach (element_children($element) as $key) {
      $element[$key]['#return_value'] = check_plain($element[$key]['#return_value']);
      $element[$key]['#name'] = $element['#name'] . '[' . $element[$key]['#return_value'] . ']';
      $element[$key]['#value_callback'] = 'select_or_other_checkbox_value';
      $element[$key]['#pre_render'][] = 'select_or_other_checkbox_prerender';
    }
  }
  return $element;
}

CommentFileSizeAuthor
#3 checkboxes-1188776-3.patch1.92 KBmattyoung

Comments

danielb’s picture

What is #multicolumn, and why do I need to put that in? I don't see it described in http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hoo...

And I don't understand your suggested solution... where is the original code from the implementation of hook_elements() :/

A bit confused by this - can you explain further please?

danielb’s picture

Also if you understand this well enough is there any reason we can't just change this:

$element['select']['#process'] = array('select_or_other_expand_checkboxes');

to this:

$element['select']['#process'][] = 'select_or_other_expand_checkboxes';

that way it won't kill the other functions off.....

but will it work properly like this? Given that I don't understand what the other process functions will do, it's a bit worrying?

mattyoung’s picture

StatusFileSize
new1.92 KB

>where is the original code from the implementation of hook_elements() :/
http://api.drupal.org/api/drupal/modules--system--system.module/function...
and I extend the "checkboxes" element with hook_elements() to make it display in columns.

>What is #multicolumn, and why do I need to put that in?

Sorry, cut and paste mistake. You don't need that.

>$element['select']['#process'] = array('select_or_other_expand_checkboxes');
>$element['select']['#process'][] = 'select_or_other_expand_checkboxes';

They both do the same and it won't work. By directly setting the #process key here, the #process functions defined by hook_elements() are "overridden". They won't be called anymore.

>Given that I don't understand what the other process functions will do, it's a bit worrying?

It doesn't matter "what the other process functions will do". What's important is modules can define/add them to do anything they want and we must not override them (unless you really really mean to but in this case, it's not).

Patch is attached (untestd).

danielb’s picture

Oh right I see what you're saying, as a patch it makes perfect sense. I'll look into it soon. Thanks.
I'll need to see if there is an equivalent problem in Drupal 7.

danielb’s picture

Status: Active » Fixed

Thanks again, I've committed that.

Status: Fixed » Closed (fixed)

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