Due to a core bug/feature, if a form element specifies a #process or #pre_render property in the render array, it's default callbacks are not added from the default element info (@see #914792: Custom element properties entirely override default element info properties).

The "solution" is to instead do the following:

$form['item'] = array(
  '#type' => 'fieldset',
  '#pre_render' => array_merge(array('bootstrap_subtheme_pre_render_fieldset'), element_info_property('fieldset', '#pre_render', array())),
);

This is, in fact, very cumbersome to do every single time. Instead, the alternative is to do a proper alter in hook_element_info_alter():

function bootstrap_subtheme_element_info_alter(&$info) {
  $info['fieldset']['#pre_render'][] = 'bootstrap_subtheme_pre_render_fieldset';
}

This too is very cumbersome. It would be much better if there were a proper "hook" system in place to automatically look for these functions and then add them in the default element info. Of course, since this would cause bootstrap_element_info_alter()to become heavy/time consuming, it will need to be cached.

There will also need to be a way to skip elements from invoking these hooks if necessary.

Comments

  • markcarver committed aaedae8 on 7.x-3.x
    Issue #2447947 by markcarver: Allow dynamic #process and #pre_render...

  • markcarver committed bfb6dd1 on 7.x-3.x
    Issue #2447947 by markcarver: Allow dynamic #process and #pre_render...

  • markcarver committed 15a0280 on
    Issue #2447947 by markcarver: Allow dynamic #process and #pre_render...
markhalliwell’s picture

Version: 7.x-3.x-dev » 8.x-3.x-dev
Assigned: Unassigned » neardark
Status: Active » Needs work
Related issues: +#2024217: Should themes be able to implement hooks, e.g. hook_system_info_alter()?

@neardark, please review when you get a chance.

Waiting on related issue for 8.x, which blocks this from actually working properly.

  • markcarver committed aaedae8 on 7.x-4.x
    Issue #2447947 by markcarver: Allow dynamic #process and #pre_render...
  • markcarver committed bfb6dd1 on 7.x-4.x
    Issue #2447947 by markcarver: Allow dynamic #process and #pre_render...
markhalliwell’s picture

Status: Needs work » Needs review

#2448843: [regression] Themes unable to implement hook_element_info_alter() is now in. This should be reviewed. I already ported the code to 8.x-3.x, but it hasn't actually been tested yet because the hook was never invoked.

markhalliwell’s picture

Version: 8.x-3.x-dev » 7.x-3.x-dev
Assigned: neardark » Unassigned
Status: Needs review » Closed (fixed)
Related issues: +#2624420: Restructure code into OO

These are now both handled by the @BootstrapProcess and @BootstrapPrerender annotations in 8.x-3.x per the work I've done in this related issue.