You are here

function units_default_form in Units of Measurement 7.2

Same name and namespace in other branches
  1. 7 units_default/units_default.pages.inc \units_default_form()

Form to manage default units and measures.

1 string reference to 'units_default_form'
units_default_menu in units_default/units_default.module
Implements hook_menu().

File

units_default/units_default.pages.inc, line 11
Page menu callbacks of Units default module.

Code

function units_default_form($form, &$form_state) {
  $settings = units_default_enabled();
  $measures = _units_default_default_units_measure();
  $units = array();
  foreach (_units_default_default_units_unit() as $v) {
    $units[$v->measure][$v->machine_name] = $v;
  }
  $form['units_default_enabled'] = array(
    '#tree' => TRUE,
  );
  foreach ($measures as $measure) {
    $class = drupal_html_class('units-default-measure-' . $measure->measure);
    $form['units_default_enabled'][$measure->measure]['measure'] = array(
      '#type' => 'checkbox',
      '#title' => entity_label($measure
        ->entityType(), $measure),
      '#attributes' => array(
        'class' => array(
          $class,
        ),
      ),
      '#return_value' => $measure->measure,
      '#default_value' => isset($settings[$measure->measure]),
    );
    $form['units_default_enabled'][$measure->measure]['units'] = array(
      '#type' => 'fieldset',
      '#title' => t('@measure units', array(
        '@measure' => entity_label($measure
          ->entityType(), $measure),
      )),
      '#collapsible' => TRUE,
      '#states' => array(
        'visible' => array(
          '.' . $class => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    if (isset($units[$measure->measure])) {
      foreach ($units[$measure->measure] as $unit) {
        $form['units_default_enabled'][$measure->measure]['units'][$unit->machine_name] = array(
          '#type' => 'checkbox',
          '#title' => entity_label($unit
            ->entityType(), $unit),
          '#description' => filter_xss($unit->description),
          '#return_value' => $unit->machine_name,
          '#default_value' => isset($settings[$measure->measure]['units'][$unit->machine_name]),
        );
      }
    }
  }
  $form = system_settings_form($form);
  $form['#validate'][] = 'units_default_form_validate';
  $form['#submit'][] = 'units_default_form_submit';
  return $form;
}