You are here

function commerce_reorder_handler_field_commerce_reorder_button::views_form in Commerce Reorder 7

Returns the form which replaces the placeholder from render().

File

includes/views/handlers/commerce_reorder_handler_field_commerce_reorder_button.inc, line 69

Class

commerce_reorder_handler_field_commerce_reorder_button

Code

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

  // The view is empty, abort.
  if (empty($this->view->result)) {
    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 base key value (for example, nid for nodes).
  foreach ($this->view->result as $row_id => $row) {
    $order_id = $this
      ->get_value($row, 'order_id');
    $form[$this->options['id']][$row_id] = array(
      '#type' => 'submit',
      '#value' => isset($this->options['reorder_button_label']) ? $this->options['reorder_button_label'] : t('Reorder'),
      '#name' => 'reorder-line-item-' . $row_id,
      '#order_id' => $order_id,
    );
  }
}