You are here

function mvf_field_widget_settings_form in Measured Value Field 7

Implements hook_field_widget_settings_form().

File

./mvf.module, line 625
Define a field type of measured value.

Code

function mvf_field_widget_settings_form($field, $instance) {
  $form = array();
  foreach ($field['settings']['meta_info'] as $subfield => $meta_info) {
    $mocked_field = mvf_field_mockup($field, $subfield);
    $mocked_instance = mvf_instance_mockup($field, $instance, $subfield);

    // Checking if the module that defines a subfield wants to define any
    // settings.
    $extra = module_invoke($mocked_instance['widget']['module'], 'field_widget_settings_form', $mocked_field, $mocked_instance);
    if (is_array($extra) && !empty($extra)) {

      // Doing any customizations before inserting output of the module that
      // defines a sub field into our widget settings form.
      switch ($subfield) {
        case 'value':
          break;
        case 'unit':
          break;
      }
      $form[$subfield] = array(
        '#type' => 'fieldset',
        '#title' => t('@label Widget Settings', array(
          '@label' => $meta_info['label'],
        )),
        '#collapsible' => TRUE,
      ) + $extra;
    }
  }
  $form['meta_info'] = array(
    '#theme' => 'mvf_column_order',
  );

  // Sort by weight the columns.
  uasort($instance['widget']['settings']['meta_info'], 'drupal_sort_weight');
  foreach ($instance['widget']['settings']['meta_info'] as $subfield => $meta_info) {
    $form['meta_info'][$subfield]['column'] = array(
      '#markup' => $field['settings']['meta_info'][$subfield]['label'],
    );

    // Any extra per sub field customizations, adjustments.
    switch ($subfield) {
      case 'unit':
        $unit_entity_info = entity_get_info('units_unit');
        $form['meta_info'][$subfield]['label_property'] = array(
          '#type' => 'select',
          '#title' => t('Label Property'),
          '#required' => TRUE,
          '#options' => array(
            $unit_entity_info['entity keys']['label'] => t('Label'),
            'symbol' => t('Symbol'),
          ),
          '#default_value' => isset($instance['widget']['settings']['meta_info'][$subfield]['label_property']) ? $instance['widget']['settings']['meta_info'][$subfield]['label_property'] : NULL,
        );
        break;
    }
    $form['meta_info'][$subfield]['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight'),
      '#title_display' => 'invisible',
      '#default_value' => isset($instance['widget']['settings']['meta_info'][$subfield]['weight']) ? $instance['widget']['settings']['meta_info'][$subfield]['weight'] : 0,
    );
  }
  return $form;
}