Right now there's a lot of code duplicated between Form Builder and Webform. Though the enhancements made in #1148808: Webform missing advanced components (add support for date component) have made it possible to pull arbitrary fields out of the original Webform configuration forms. There's still quite a bit that we could do.

One of the things that's both fragile and verbose is the declaration of default fields for Webform. For example defining the default date field looks like this:

    'default' => array(
      '#title' => t('New date'),
      '#type' => 'date',
      '#theme_wrappers' => array('webform_element'),
      '#form_builder' => array('element_type' => 'date'),
      '#title_display' => 'before',
      '#year_start' => '-2',
      '#year_end' => '+2',
      '#process' => array('webform_expand_date'),
      '#theme' => 'webform_date',
    ),

But all of those defaults are already provided by the date component, why not pull out the defaults and then pass it directly into render? This patch generalizes this approach and makes it so that defining the default for fields now looks like this instead:

  $fields['date']['default'] = _form_builder_webform_default('date');

Besides reducing duplicated code and maintaining a more consistent experience between Form Builder and non-Form Builder user, it also reduces differences between Drupal branches.

Comments

quicksketch’s picture

I changed the approach used here slightly to removed the "assumed default" #title property, since it was inconsistently used and resulted in slightly clunkier default titles and added difficulty when translating. Committed to both branches.

quicksketch’s picture

Status: Needs review » Fixed

The D7 patch accidentally also contained #1150372: Toolbar in Drupal 7 covers up field palette when scrolling. I removed it before committing.

Status: Fixed » Closed (fixed)

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