class views_bulk_operations_handler_field_operations in Views Bulk Operations (VBO) 7.3
@file Views field handler. Contains all relevant VBO options and related logic. Implements the Views Form API.
Hierarchy
- class \views_object
- class \views_handler
Expanded class hierarchy of views_bulk_operations_handler_field_operations
1 string reference to 'views_bulk_operations_handler_field_operations'
- views_bulk_operations_views_data_alter in views/
views_bulk_operations.views.inc - Implements hook_views_data_alter().
File
- views/
views_bulk_operations_handler_field_operations.inc, line 9 - Views field handler. Contains all relevant VBO options and related logic. Implements the Views Form API.
View source
class views_bulk_operations_handler_field_operations extends views_handler_field_entity {
var $revision = FALSE;
function init(&$view, &$options) {
parent::init($view, $options);
// Update old settings
if (!empty($options['vbo']) && empty($this->options['vbo_operations'])) {
$this->options['vbo_operations'] = $options['vbo']['operations'];
unset($options['vbo']['operations']);
$this->options['vbo_settings'] = $options['vbo'] + $this->options['vbo_settings'];
}
// When updating old Views it is possible for this value to stay empty.
if (empty($this->options['vbo_settings']['entity_load_capacity'])) {
$this->options['vbo_settings']['entity_load_capacity'] = 10;
}
foreach ($this->options['vbo_operations'] as $operation_id => &$operation_options) {
// Prefix all un-prefixed operations.
if (strpos($operation_id, '::') === FALSE) {
$operations = views_bulk_operations_get_operation_info();
// Basically, guess.
foreach (array(
'action',
'rules_component',
) as $operation_type) {
$new_operation_id = $operation_type . '::' . $operation_id;
if (isset($operations[$new_operation_id])) {
$this->options['vbo_operations'][$new_operation_id] = $operation_options;
break;
}
}
// Remove the old operation in any case.
unset($this->options['vbo_operations'][$operation_id]);
}
// Rename the use_queue setting.
if (isset($operation_options['use_queue']) && !isset($operation_options['postpone_processing'])) {
$operation_options['postpone_processing'] = $operation_options['use_queue'];
unset($operation_options['use_queue']);
}
}
// Check whether this is a revision.
$table_data = views_fetch_data($this->table);
if (!empty($table_data['table']['revision'])) {
$this->revision = TRUE;
}
}
function option_definition() {
$options = parent::option_definition();
$options['vbo_settings'] = array(
'contains' => array(
'display_type' => array(
'default' => 0,
),
'enable_select_all_pages' => array(
'default' => TRUE,
),
'enable_select_this_page' => array(
'default' => TRUE,
),
'row_clickable' => array(
'default' => TRUE,
),
'force_single' => array(
'default' => FALSE,
),
'entity_load_capacity' => array(
'default' => 10,
),
'skip_batching' => array(
'default' => 0,
),
'save_view_object_when_batching' => array(
'default' => 0,
),
),
);
$options['vbo_operations'] = array(
'default' => array(),
'unpack_translatable' => 'unpack_operations',
'export' => 'export_vbo_operations',
);
return $options;
}
function export_vbo_operations($indent, $prefix, $storage, $option, $definition, $parents) {
// Anti-recursion, since we use the parent export helper.
unset($definition['export']);
// Find and remove all unselected/disabled operations.
foreach ($storage['vbo_operations'] as $operation_id => $operation) {
if (empty($operation['selected'])) {
unset($storage['vbo_operations'][$operation_id]);
}
}
return parent::export_option($indent, $prefix, $storage, $option, $definition, $parents);
}
function unpack_operations(&$translatable, $storage, $option, $definition, $parents, $keys) {
$translatable[] = array(
'value' => t('- Choose an operation -'),
'keys' => array_merge($keys, array(
'noop',
)),
);
foreach ($storage[$option] as $key => $operation) {
if (!empty($operation['override_label']) && !empty($operation['label'])) {
$translatable[] = array(
'value' => $operation['label'],
'keys' => array_merge($keys, array(
$key,
)),
);
}
}
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['vbo_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Bulk operations settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['vbo_settings']['display_type'] = array(
'#type' => 'radios',
'#title' => t('Display operations as'),
'#default_value' => $this->options['vbo_settings']['display_type'],
'#options' => array(
t('Dropdown selectbox with Submit button'),
t('Each action as a separate button'),
),
);
$form['vbo_settings']['enable_select_all_pages'] = array(
'#type' => 'checkbox',
'#title' => t('Enable "Select all items on all pages"'),
'#default_value' => $this->options['vbo_settings']['enable_select_all_pages'],
'#description' => t('Check this box to enable the ability to select all items on all pages.'),
);
$form['vbo_settings']['enable_select_this_page'] = array(
'#type' => 'checkbox',
'#title' => t('Enable "Select all items on this page"'),
'#default_value' => $this->options['vbo_settings']['enable_select_this_page'],
'#description' => t('Check this box to enable the ability to select all items on current page.'),
);
$form['vbo_settings']['row_clickable'] = array(
'#type' => 'checkbox',
'#title' => t('Make the whole row clickable'),
'#default_value' => $this->options['vbo_settings']['row_clickable'],
'#description' => t('Check this box to select an item when its row has been clicked. Requires JavaScript.'),
);
$form['vbo_settings']['force_single'] = array(
'#type' => 'checkbox',
'#title' => t('Force single'),
'#default_value' => $this->options['vbo_settings']['force_single'],
'#description' => t('Check this box to restrict selection to a single value.'),
);
$form['vbo_settings']['entity_load_capacity'] = array(
'#type' => 'textfield',
'#title' => t('Number of entities to load at once'),
'#description' => t("Improve execution performance at the cost of memory usage. Set to '1' if you're having problems."),
'#default_value' => $this->options['vbo_settings']['entity_load_capacity'],
);
$form['vbo_settings']['skip_batching'] = array(
'#type' => 'checkbox',
'#title' => t('Skip batching'),
'#default_value' => $this->options['vbo_settings']['skip_batching'],
'#description' => '<b>' . t('Warning:') . '</b> ' . t('This will cause timeouts for larger amounts of selected items.'),
);
$form['vbo_settings']['save_view_object_when_batching'] = array(
'#type' => 'checkbox',
'#title' => t('Save the whole view object when batching'),
'#default_value' => $this->options['vbo_settings']['save_view_object_when_batching'],
'#description' => '<b>' . t('Warning:') . '</b> ' . t('Use this option when your view contains query conditions which are not defined as arguments.'),
);
// Display operations and their settings.
$form['vbo_operations'] = array(
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => t('Selected bulk operations'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$entity_type = $this
->get_entity_type();
$options = $this->options['vbo_operations'];
foreach (views_bulk_operations_get_applicable_operations($entity_type, $options) as $operation_id => $operation) {
$operation_options = !empty($options[$operation_id]) ? $options[$operation_id] : array();
$dom_id = 'edit-options-vbo-operations-' . str_replace(array(
'_',
':',
), array(
'-',
'',
), $operation_id);
$form['vbo_operations'][$operation_id]['selected'] = array(
'#type' => 'checkbox',
'#title' => $operation
->adminLabel(),
'#default_value' => !empty($operation_options['selected']),
);
if (!$operation
->aggregate()) {
$form['vbo_operations'][$operation_id]['postpone_processing'] = array(
'#type' => 'checkbox',
'#title' => t('Enqueue the operation instead of executing it directly'),
'#default_value' => !empty($operation_options['postpone_processing']),
'#dependency' => array(
$dom_id . '-selected' => array(
1,
),
),
);
}
$form['vbo_operations'][$operation_id]['skip_confirmation'] = array(
'#type' => 'checkbox',
'#title' => t('Skip confirmation step'),
'#default_value' => !empty($operation_options['skip_confirmation']),
'#dependency' => array(
$dom_id . '-selected' => array(
1,
),
),
);
$form['vbo_operations'][$operation_id]['skip_permission_check'] = array(
'#type' => 'checkbox',
'#title' => t('Skip permission step'),
'#default_value' => !empty($operation_options['skip_permission_check']),
'#dependency' => array(
$dom_id . '-selected' => array(
1,
),
),
);
$form['vbo_operations'][$operation_id] += $operation
->adminOptionsForm($dom_id, $this);
}
}
function options_validate(&$form, &$form_state) {
parent::options_validate($form, $form_state);
$entity_type = $this
->get_entity_type();
foreach ($form_state['values']['options']['vbo_operations'] as $operation_id => &$options) {
if (empty($options['selected'])) {
continue;
}
$operation = views_bulk_operations_get_operation($operation_id, $entity_type, $options);
$fake_form = $form['vbo_operations'][$operation_id];
$fake_form_state = array(
'values' => &$options,
);
$error_element_base = 'vbo_operations][' . $operation_id . '][';
$operation
->adminOptionsFormValidate($fake_form, $fake_form_state, $error_element_base);
}
}
function options_submit(&$form, &$form_state) {
parent::options_submit($form, $form_state);
$entity_type = $this
->get_entity_type();
foreach ($form_state['values']['options']['vbo_operations'] as $operation_id => &$options) {
if (empty($options['selected'])) {
continue;
}
$operation = views_bulk_operations_get_operation($operation_id, $entity_type, $options);
$fake_form = $form['vbo_operations'][$operation_id];
$fake_form_state = array(
'values' => &$options,
);
$operation
->adminOptionsFormSubmit($fake_form, $fake_form_state);
}
}
/**
* Returns the value of a vbo option.
*/
function get_vbo_option($key, $default = NULL) {
return isset($this->options['vbo_settings'][$key]) ? $this->options['vbo_settings'][$key] : $default;
}
/**
* If the view is using a table style, provide a
* placeholder for a "select all" checkbox.
*/
function label() {
if (!empty($this->view->style_plugin) && $this->view->style_plugin instanceof views_plugin_style_table && !$this->options['vbo_settings']['force_single']) {
return '<!--views-bulk-operations-select-all-->';
}
else {
return parent::label();
}
}
function render($values) {
return '<!--form-item-' . $this->options['id'] . '--' . $this->view->row_index . '-->';
}
/**
* The form which replaces the placeholder from render().
*/
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_index => $row) {
$this->view->row_index = $row_index;
$id = $this
->get_value($row, $this->real_field);
if ($this->options['vbo_settings']['force_single']) {
$form[$this->options['id']][$row_index] = array(
'#type' => 'radio',
'#parents' => array(
$this->options['id'],
),
'#return_value' => $id,
'#attributes' => array(
'class' => array(
'vbo-select',
),
),
);
}
else {
$form[$this->options['id']][$row_index] = array(
'#type' => 'checkbox',
'#return_value' => $id,
'#default_value' => FALSE,
'#attributes' => array(
'class' => array(
'vbo-select',
),
),
);
}
}
}
public function get_selected_operations() {
global $user;
$selected = drupal_static(__FUNCTION__);
if (!isset($selected)) {
$entity_type = $this
->get_entity_type();
$selected = array();
foreach ($this->options['vbo_operations'] as $operation_id => $options) {
if (empty($options['selected'])) {
continue;
}
$operation = views_bulk_operations_get_operation($operation_id, $entity_type, $options);
if (!$operation) {
continue;
}
$skip_permission_check = $operation
->getAdminOption('skip_permission_check', FALSE);
if (!$operation
->access($user) && !$skip_permission_check) {
continue;
}
$selected[$operation_id] = $operation;
}
}
return $selected;
}
/**
* Returns the options stored for the provided operation id.
*/
public function get_operation_options($operation_id) {
$options = $this->options['vbo_operations'];
return isset($options[$operation_id]) ? $options[$operation_id] : array();
}
/**
* Determine the base table of the VBO field, and then use it to determine
* the entity type that VBO is operating on.
*/
public function get_entity_type() {
return $this->entity_type;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
views_bulk_operations_handler_field_operations:: |
property | |||
views_bulk_operations_handler_field_operations:: |
function | |||
views_bulk_operations_handler_field_operations:: |
public | function | Determine the base table of the VBO field, and then use it to determine the entity type that VBO is operating on. | |
views_bulk_operations_handler_field_operations:: |
public | function | Returns the options stored for the provided operation id. | |
views_bulk_operations_handler_field_operations:: |
public | function | ||
views_bulk_operations_handler_field_operations:: |
function | Returns the value of a vbo option. | ||
views_bulk_operations_handler_field_operations:: |
function |
Initialize the entity type. Overrides views_handler_field_entity:: |
||
views_bulk_operations_handler_field_operations:: |
function |
If the view is using a table style, provide a
placeholder for a "select all" checkbox. Overrides views_handler_field:: |
||
views_bulk_operations_handler_field_operations:: |
function |
Default options form provides the label widget that all fields should have. Overrides views_handler_field:: |
||
views_bulk_operations_handler_field_operations:: |
function |
Performs some cleanup tasks on the options array before saving it. Overrides views_handler_field:: |
||
views_bulk_operations_handler_field_operations:: |
function |
Validate the options form. Overrides views_handler:: |
||
views_bulk_operations_handler_field_operations:: |
function |
Information about options for all kinds of purposes will be held here. Overrides views_handler_field:: |
||
views_bulk_operations_handler_field_operations:: |
function |
Render the field. Overrides views_handler_field:: |
||
views_bulk_operations_handler_field_operations:: |
function | |||
views_bulk_operations_handler_field_operations:: |
function | The form which replaces the placeholder from render(). | ||
views_handler:: |
public | property | The type of the handler, for example filter/footer/field. | |
views_handler:: |
public | property | Where the $query object will reside:. | 1 |
views_handler:: |
public | property | The actual field in the database table, maybe different on other kind of query plugins/special handlers. | |
views_handler:: |
public | property | The relationship used for this field. | |
views_handler:: |
public | property | The alias of the table of this handler which is used in the query. | |
views_handler:: |
public | property |
The top object of a view. Overrides views_object:: |
|
views_handler:: |
public | function | Take input from exposed handlers and assign to this handler, if necessary. | 1 |
views_handler:: |
public | function | Check whether current user has access to this handler. | 10 |
views_handler:: |
public | function | Determine if the handler is considered 'broken'. | 6 |
views_handler:: |
public | function | Determine if a handler can be exposed. | 2 |
views_handler:: |
public | function | Transform a string by a certain method. | |
views_handler:: |
public | function | Ensure the main table for this handler is in the query. This is used a lot. | 8 |
views_handler:: |
public | function | Render our chunk of the exposed handler form when selecting. | 1 |
views_handler:: |
public | function | Get information about the exposed form for the form renderer. | 1 |
views_handler:: |
public | function | Submit the exposed handler form. | |
views_handler:: |
public | function | Validate the exposed handler form. | 4 |
views_handler:: |
public | function | Form for exposed handler options. | 2 |
views_handler:: |
public | function | Set new exposed option defaults when exposed setting is flipped on. | 2 |
views_handler:: |
public | function | Perform any necessary changes to the form exposes prior to storage. There is no need for this function to actually store the data. | |
views_handler:: |
public | function | Validate the options form. | 1 |
views_handler:: |
public | function | Provide defaults for the handler. | |
views_handler:: |
public | function | Provide a form for setting options. | 1 |
views_handler:: |
public | function | Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data. | |
views_handler:: |
public | function | Validate the options form. | |
views_handler:: |
public | function | Shortcut to get a handler's raw field value. | |
views_handler:: |
public | function | Get the join object that should be used for this handler. | |
views_handler:: |
public | function | Provide a form for aggregation settings. | 1 |
views_handler:: |
public | function | Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data. | 1 |
views_handler:: |
public | function | If a handler has 'extra options' it will get a little settings widget and another form called extra_options. | 1 |
views_handler:: |
public | function | Returns TRUE if the exposed filter works like a grouped filter. | 1 |
views_handler:: |
public | function | Determine if this item is 'exposed', meaning it provides form elements to let users modify the view. | |
views_handler:: |
public | function | Define if the exposed input has to be submitted multiple times. This is TRUE when exposed filters grouped are using checkboxes as widgets. | 1 |
views_handler:: |
public | function | Determine if the argument needs a style plugin. | 1 |
views_handler:: |
public | function | Provides a unique placeholders for handlers. | |
views_handler:: |
public | function | Run after the view is executed, before the result is cached. | 1 |
views_handler:: |
public | function | Run before the view is built. | 1 |
views_handler:: |
public | function | Sanitize the value for output. | |
views_handler:: |
public | function | Called just prior to query(), this lets a handler set up any relationship it needs. | |
views_handler:: |
public | function | Shortcut to display the expose/hide button. | 2 |
views_handler:: |
public | function | Shortcut to display the exposed options form. | |
views_handler:: |
public | function | If set to remember exposed input in the session, store it there. | 1 |
views_handler:: |
public | function | Provides the handler some groupby. | 2 |
views_handler:: |
public | function | Validates the handler against the complete View. | 1 |
views_handler_field:: |
public | property | Stores additional fields which get added to the query. The generated aliases are stored in $aliases. | |
views_handler_field:: |
public | property | ||
views_handler_field:: |
public | property | ||
views_handler_field:: |
protected | property | Keeps track of the last render index. | |
views_handler_field:: |
public | property | The field value prior to any rewriting. | |
views_handler_field:: |
public | function | Add 'additional' fields to the query. | |
views_handler_field:: |
public | function | Add any special tokens this field might use for itself. | 4 |
views_handler_field:: |
public | function |
Provide extra data to the administration form Overrides views_handler:: |
|
views_handler_field:: |
public | function | Render a field using advanced settings. | |
views_handler_field:: |
public | function | Determine if this field can allow advanced rendering. | 1 |
views_handler_field:: |
public | function | Called to determine what to tell the clicksorter. | 1 |
views_handler_field:: |
public | function | Determine if this field is click sortable. | 1 |
views_handler_field:: |
public | function |
Construct a new field handler. Overrides views_object:: |
17 |
views_handler_field:: |
public | function | Document any special tokens this field might use for itself. | 4 |
views_handler_field:: |
public | function | Return the class of the field. | |
views_handler_field:: |
public | function | Return the class of the field's label. | |
views_handler_field:: |
public | function | Return an HTML element for the label based upon the field's element type. | |
views_handler_field:: |
public | function | Return an HTML element based upon the field's element type. | 2 |
views_handler_field:: |
public | function | Return the class of the field's wrapper. | |
views_handler_field:: |
public | function | Return an HTML element for the wrapper based upon the field's element type. | |
views_handler_field:: |
public | function | Provide a list of elements valid for field HTML. | |
views_handler_field:: |
public | function | Get the 'render' tokens to use for advanced rendering. | |
views_handler_field:: |
public | function | Recursive function to add replacements for nested query string parameters. | |
views_handler_field:: |
public | function | Checks if a field value is empty. | |
views_handler_field:: |
public | function | Render this field as altered text, from a fieldset set by the user. | |
views_handler_field:: |
public | function | Render this field as a link, with info from a fieldset set by the user. | |
views_handler_field:: |
public | function | Perform an advanced text render for the item. | |
views_handler_field:: |
public | function | Trim the field down to the specified length. | |
views_handler_field:: |
public | function | Call out to the theme() function. | |
views_handler_field:: |
public | function | Build a list of suitable theme functions for this view. | |
views_handler_field:: |
public | function | Replace a value with tokens from the last field. | |
views_handler_field:: |
public | function |
Return a string representing this handler's name in the UI. Overrides views_handler:: |
1 |
views_handler_field:: |
public | function | Determines if this field will be available as an option to group the result by in the style settings. | |
views_handler_field_entity:: |
public | property | The base field of the entity type assosiated with this field. | |
views_handler_field_entity:: |
public | property | Stores all entites which are in the result. | |
views_handler_field_entity:: |
public | property | Stores the entity type which is loaded by this field. | |
views_handler_field_entity:: |
public | function |
Return the entity object or a certain property of the entity. Overrides views_handler_field:: |
|
views_handler_field_entity:: |
public | function |
Load the entities for all rows that are about to be displayed. Overrides views_handler_field:: |
|
views_handler_field_entity:: |
public | function |
Overriden to add the field for the entity id. Overrides views_handler_field:: |
2 |
views_object:: |
public | property | Handler's definition. | |
views_object:: |
public | property | Except for displays, options for the object will be held here. | 1 |
views_object:: |
function | Collect this handler's option definition and alter them, ready for use. | ||
views_object:: |
public | function | Destructor. | 2 |
views_object:: |
public | function | 1 | |
views_object:: |
public | function | ||
views_object:: |
public | function | Always exports the option, regardless of the default value. | |
views_object:: |
public | function | Set default options on this object. | 1 |
views_object:: |
public | function | Set default options. | |
views_object:: |
public | function | Let the handler know what its full definition is. | |
views_object:: |
public | function | Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away. | |
views_object:: |
public | function | Unpack a single option definition. | |
views_object:: |
public | function | Unpacks each handler to store translatable texts. | |
views_object:: |
public | function |