function views_db_object::add_item
3.x view.inc | views_db_object::add_item($display_id, $type, $table, $field, $options = array(), $id = NULL) |
2.x view.inc | views_db_object::add_item($display_id, $type, $table, $field, $options = array(), $id = NULL) |
Add an item with a handler to the view.
These items may be fields, filters, sort criteria, or arguments.
File
Class
- views_db_object
- Base class for views' database objects.
Code
function add_item($display_id, $type, $table, $field, $options = array(), $id = NULL) {
$types = views_object_types();
$this->set_display($display_id);
$fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']);
if (empty($id)) {
$count = 0;
$id = $field;
while (!empty($fields[$id])) {
$id = $field . '_' . ++$count;
}
}
$new_item = array(
'id' => $id,
'table' => $table,
'field' => $field,
) + $options;
$handler = views_get_handler($table, $field, $type);
$fields[$id] = $new_item;
$this->display[$display_id]->handler->set_option($types[$type]['plural'], $fields);
return $id;
}