You are here

class uc_product_handler_field_weight in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_product/views/uc_product_handler_field_weight.inc \uc_product_handler_field_weight

Returns a formatted weight value to display in the View.

Hierarchy

Expanded class hierarchy of uc_product_handler_field_weight

1 string reference to 'uc_product_handler_field_weight'
uc_product_views_data in uc_product/views/uc_product.views.inc
Implements hook_views_data().

File

uc_product/views/uc_product_handler_field_weight.inc, line 11
Views handler: Product weight field.

View source
class uc_product_handler_field_weight extends views_handler_field_numeric {

  /**
   * Overrides views_handler::option_definition().
   */
  function option_definition() {
    $options = parent::option_definition();
    $options['format'] = array(
      'default' => 'uc_weight',
    );
    return $options;
  }

  /**
   * Overrides views_handler::options_form().
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $options = $this->options;
    $form['format'] = array(
      '#title' => t('Format'),
      '#type' => 'radios',
      '#options' => array(
        'uc_weight' => t('Ubercart weight'),
        'numeric' => t('Numeric'),
      ),
      '#default_value' => $options['format'],
      '#weight' => 1,
    );

    // Change weight and dependency of the previous field on the parent numeric ones
    $weight = 2;
    foreach (array(
      'set_precision',
      'precision',
      'decimal',
      'separator',
      'prefix',
      'suffix',
    ) as $field) {
      $form[$field]['#process'] = array(
        'views_process_dependency',
      );
      if (is_array($form[$field]['#dependency'])) {
        $form[$field]['#dependency'] += array(
          'radio:options[format]' => array(
            'numeric',
          ),
        );
        $form[$field]['#dependency_count'] = count($form[$field]['#dependency']);
      }
      else {
        $form[$field]['#dependency'] = array(
          'radio:options[format]' => array(
            'numeric',
          ),
        );
      }
      $form[$field]['#weight'] = ++$weight;
    }
  }

  /**
   * Overrides views_handler_field::render().
   */
  function render($values) {
    if ($this->options['format'] == 'numeric') {
      return parent::render($values);
    }
    if ($this->options['format'] == 'uc_weight') {
      return uc_weight_format($values->{$this->field_alias}, $values->{$this->aliases['weight_units']});
    }
  }

}

Members