You are here

function merci_line_item_handler_field_edit_delete::views_form in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

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

File

merci_line_item/includes/views/handlers/merci_line_item_handler_field_edit_delete.inc, line 30
Field handler to present a button to remove a line item. It's a dummy handler, most part of the implementation is done via pre and post render hooks.

Class

merci_line_item_handler_field_edit_delete
Field handler to present a button to delete a line item.

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) {
    $line_item_id = $this
      ->get_value($row);
    $form[$this->options['id']][$row_id] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#name' => 'delete-line-item-' . $row_id,
      '#attributes' => array(
        'class' => array(
          'delete-line-item',
        ),
      ),
      '#line_item_id' => $line_item_id,
      '#submit' => array_merge($form['#submit'], array(
        'merci_line_item_line_item_views_delete_form_submit',
      )),
    );
  }
}