Follow-up to: #1812724: Consolidate all form element templates and add theme_hook_suggestons

Problem

As contained and clarified at the bottom of the change notice:

  • INPUT form element #types have a #pre_render callback, which translates the render element into theme variables.
  • The registered #pre_render callback for each form element in system_element_info() is essential, since it processes the render element #properties into #attributes.
  • Due to the way default element #properties are merged into element definitions, a form element definition like this omits the #pre_render callback:

    <?php
      $form
    ['foo'] = array(
       
    '#type' => 'textfield',
       
    '#pre_render' => array('mymodule_pre_render_foo'),
      );
    ?>

    You have to manually ensure to include the required #pre_render:

    <?php
      $form
    ['foo'] = array(
       
    '#type' => 'textfield',
       
    '#pre_render' => array_merge(array('mymodule_pre_render_foo'), element_info_property('textfield', '#pre_render', array())),
      );
    ?>

Goal

  • Introduce a new render element #property that defines a single callback to prepare and translate a render element for #theme.
Files: 
CommentFileSizeAuthor
Screen Shot 2013-01-17 at 14.11.50.png108.79 KBswentel

Comments

sun’s picture

Issue summary:View changes

Updated issue summary.

tim.plunkett’s picture

Priority:Major» Normal

The issue summary doesn't make this clear why it is major. Nothing in core has to use the above pattern, if its a problem we should have a test module to illustrate it.

sun’s picture

Priority:Normal» Major

To spell out the problem in KISS:

  1. <?php
    $form
    ['foo'] = array(
     
    '#type' => 'textfield',
     
    '#pre_render' => array('mymodule_prerender_foo'),
    );
    ?>
  2. Kaboom.
tim.plunkett’s picture

Version:8.x-dev» 9.x-dev
tim.plunkett’s picture

Issue summary:View changes

Updated issue summary.

catch’s picture

Version:9.x-dev» 8.1.x-dev
Issue summary:View changes
Issue tags:-API clean-up+API addition