function commerce_line_item_handler_field_edit_quantity::views_form in Commerce Core 7
Returns the form which replaces the placeholder from render().
File
- modules/
line_item/ includes/ views/ handlers/ commerce_line_item_handler_field_edit_quantity.inc, line 31 - Field handler to present a form field to change quantity of a line item. It's a dummy handler, most part of the implementation is done via post render hook.
Class
- commerce_line_item_handler_field_edit_quantity
- Field handler to present a field to change quantity of 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, 'line_item_id');
$quantity = $this
->get_value($row, 'quantity');
$form[$this->options['id']][$row_id] = array(
'#type' => 'textfield',
'#datatype' => 'integer',
'#default_value' => round($quantity),
'#size' => 4,
// The line item database schema limits the quantity to 8 numerals for
// integer quantities. For fractional quantities, we'd support decimal
// places, but without knowing if a site supports them or not, the
// safest option for this field's supported input length is 8; but a
// malicious user could still create a problem insert by using the max
// quantity on a price so it breaks the total allowed amount. If a site
// has been customized to support larger quantity values, this property
// can still be overridden via a form alter.
'#maxlength' => 6,
'#line_item_id' => $line_item_id,
'#attributes' => array(
'title' => $this->options['label'],
),
);
}
}