You are here

public function commerce_add_to_cart_extras_handler_field_quantity::views_form in Commerce Add to Cart Extras 7

The form which replaces the placeholder from render().

File

./commerce_add_to_cart_extras_handler_field_quantity.inc, line 101
Views field handler. Adds the quantity field to the view. Implements the Views Form API.

Class

commerce_add_to_cart_extras_handler_field_quantity
Views field handler.

Code

public function views_form(&$form, &$form_state) {

  // The view is empty, abort.
  if (empty($this->view->result)) {
    $form['#access'] = FALSE;
    return;
  }
  $form[$this->options['id']] = array(
    '#tree' => TRUE,
  );

  // At this point, the query has already been run, so we can access the
  // results in order to get the product_id.
  foreach ($this->view->result as $row_index => $row) {
    $product_id = $this
      ->get_value($row);
    $form[$this->options['id']][$row_index] = array(
      '#type' => 'textfield',
      '#product_id' => $product_id,
      '#default_value' => $this->options['default_quantity'],
      '#size' => 5,
    );
  }
}