Detect default values and exclude from output

webchick - November 15, 2005 - 08:48
Project:Form Updater
Version:HEAD
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Amazon had asked me to look at this module and make suggestions if I found them, so here was one. Flipping AWESOME script, by the way. :)

It would be cool if this tool could check an element's default values (these can be found in system_elements) to determine if an attribute matches a default value, and if so remove it from the output.

Here's an example from project.module:

form_checkbox(t('Browse projects by releases'), 'project_browse_releases', 1, variable_get('project_browse_releases', 1), t('Checking this box will cause the project browsing page to have version subtabs.'));

turned into:

$form['project_browse_releases'] = array(
  '#type' => 'checkbox',
  '#title' => t('Browse projects by releases'),
  '#return_value' => 1,
  '#default_value' => variable_get('project_browse_releases', 1),
  '#description' => t('Checking this box will cause the project browsing page to have version subtabs.'),
);

However, #return_value already defaults to 1, so it is not required. Output would ideally look like:

$form['project_browse_releases'] = array(
  '#type' => 'checkbox',
  '#title' => t('Browse projects by releases'),
  '#default_value' => variable_get('project_browse_releases', 1),
  '#description' => t('Checking this box will cause the project browsing page to have version subtabs.'),
);

Now that the default values in system_elements are fairly reasonable, it might be cool to implement a feature like this.

 
 

Drupal is a registered trademark of Dries Buytaert.