security update for views views_bulk_operations

This commit is contained in:
2019-04-23 16:18:52 +02:00
parent 200a1093e8
commit 3c1b4f164e
422 changed files with 13719 additions and 6819 deletions
View File
@@ -3,10 +3,14 @@
/**
* @file
* Provides an action for creating a zip archive of selected files.
*
* An entry in the {file_managed} table is created for the newly created archive,
* and it is marked as permanent or temporary based on the operation settings.
*/
/**
* Implements hook_action_info().
*/
function views_bulk_operations_archive_action_info() {
$actions = array();
if (function_exists('zip_open')) {
@@ -18,6 +22,7 @@ function views_bulk_operations_archive_action_info() {
// "Create an advanced action" dropdown on admin/config/system/actions.
'configurable' => FALSE,
'vbo_configurable' => TRUE,
'behavior' => array('views_property'),
'triggers' => array('any'),
);
}
@@ -70,6 +75,10 @@ function views_bulk_operations_archive_action($file, $context) {
$archive_file->filemime = file_get_mimetype($destination);
$archive_file->uid = $user->uid;
$archive_file->status = $context['settings']['temporary'] ? FALSE : FILE_STATUS_PERMANENT;
// Clear filesize() cache to avoid private file system differences in
// filesize.
// @see https://www.drupal.org/node/2743999
clearstatcache();
file_save($archive_file);
$url = file_create_url($archive_file->uri);
@@ -99,8 +108,11 @@ function views_bulk_operations_archive_action_form($context) {
}
/**
* Assembles a sanitized and unique URI for the archive, and returns it for
* usage by the action callback (views_bulk_operations_archive_action).
* Assembles a sanitized and unique URI for the archive.
*
* @returns array
* A URI array used by the action callback
* (views_bulk_operations_archive_action).
*/
function views_bulk_operations_archive_action_submit($form, $form_state) {
// Validate the scheme, fallback to public if it's somehow invalid.
@@ -155,10 +167,12 @@ function views_bulk_operations_archive_action_views_bulk_operations_form($option
/**
* Create a sanitized and unique version of the provided filename.
*
* @param $filename
* String filename
* @param string $filename
* The filename to create.
* @param array $archive_list
* The list of files already in the archive.
*
* @return
* @return string
* The new filename.
*/
function _views_bulk_operations_archive_action_create_filename($filename, $archive_list) {
@@ -166,7 +180,7 @@ function _views_bulk_operations_archive_action_create_filename($filename, $archi
// some filesystems, not many applications handle them well.
$filename = preg_replace('/[\x00-\x1F]/u', '_', $filename);
if (substr(PHP_OS, 0, 3) == 'WIN') {
// These characters are not allowed in Windows filenames
// These characters are not allowed in Windows filenames.
$filename = str_replace(array(':', '*', '?', '"', '<', '>', '|'), '_', $filename);
}
@@ -13,11 +13,13 @@ function views_bulk_operations_book_action_info() {
'label' => t('Move to book'),
'configurable' => TRUE,
'behavior' => array('changes_property'),
'triggers' => array('any'),
);
$actions['views_bulk_operations_remove_from_book_action'] = array(
'type' => 'node',
'label' => t('Remove from book'),
'configurable' => FALSE,
'triggers' => array('any'),
);
}
@@ -56,9 +58,9 @@ function views_bulk_operations_move_to_book_action_submit($form, $form_state) {
function views_bulk_operations_move_to_book_action($node, $context = array()) {
if (isset($context['book'])) {
$book_node = node_load($context['book']);
$mlid = db_select('menu_links' , 'ml')
->condition('ml.link_path' , 'node/' . $node->nid)
->fields('ml' , array('mlid'))
$mlid = db_select('menu_links', 'ml')
->condition('ml.link_path', 'node/' . $node->nid)
->fields('ml', array('mlid'))
->execute()
->fetchField();
$node->book['mlid'] = $mlid;
@@ -69,9 +71,10 @@ function views_bulk_operations_move_to_book_action($node, $context = array()) {
}
/**
* Adds the action 'Remove node from a parent book'
* Adds the action 'Remove node from a parent book'.
*/
function views_bulk_operations_remove_from_book_action($node, $context) {
$book = $node->book['mlid'];
function views_bulk_operations_remove_from_book_action($node) {
book_node_delete($node);
// Remove book to avoid book_node_update() from building the links again.
unset($node->book);
}
@@ -0,0 +1,65 @@
<?php
/**
* @file
* Implements a generic entity change owner action.
*/
/**
* Implements hook_action_info().
*/
function views_bulk_operations_change_owner_action_info() {
return array(
'views_bulk_operations_change_owner_action' => array(
'type' => 'entity',
'label' => t('Change owner'),
'configurable' => TRUE,
'behavior' => array('changes_property'),
'triggers' => array('any'),
),
);
}
/**
* Action function.
*/
function views_bulk_operations_change_owner_action($entity, $context) {
$entity->uid = $context['owner_uid'];
}
/**
* Action form function.
*/
function views_bulk_operations_change_owner_action_form($context, &$form_state) {
$form['owner_username'] = array(
'#type' => 'textfield',
'#maxlength' => USERNAME_MAX_LENGTH,
'#title' => t('Owner'),
'#required' => TRUE,
'#description' => t('Choose the user you would like to set as the owner.'),
'#autocomplete_path' => 'user/autocomplete',
);
return $form;
}
/**
* Action form validate function.
*
* Checks that the submitted text is a valid username.
*/
function views_bulk_operations_change_owner_action_validate($form, $form_state) {
if (!user_load_by_name($form_state['values']['owner_username'])) {
form_set_error('owner_username', t('Valid username required.'));
}
}
/**
* Action form submit function.
*
* Pass submitted username back to views_bulk_operations_change_owner.
*/
function views_bulk_operations_change_owner_action_submit($form, $form_state) {
$user = user_load_by_name($form_state['values']['owner_username']);
return array('owner_uid' => $user->uid);
}
@@ -19,15 +19,51 @@ function views_bulk_operations_delete_action_info() {
'label' => t('Delete revision'),
'configurable' => FALSE,
'behavior' => array('deletes_property'),
'triggers' => array('any'),
),
);
}
function views_bulk_operations_delete_item_views_bulk_operations_form($settings) {
$form = array();
$form['log'] = array(
'#type' => 'checkbox',
'#title' => t('Log individual deletions'),
'#description' => t('Note: Deleting large amounts of entities will generate large amounts of log messages.'),
'#default_value' => !empty($settings['log']),
);
return $form;
}
function views_bulk_operations_delete_item($entity, $context) {
$info = entity_get_info($context['entity_type']);
$entity_id = $entity->{$info['entity keys']['id']};
entity_delete($context['entity_type'], $entity_id);
// Add a message to the watchdog if we've been configured to do so.
if (!empty($context['settings']['log'])) {
// Log an appropriate message for this entity type, using the format from
// the node, taxonomy and user module for their entity types.
switch ($context['entity_type']) {
case 'node':
watchdog('content', '@type: deleted %title.', array('@type' => $entity->type, '%title' => $entity->title));
break;
case 'taxonomy_term':
watchdog('taxonomy', 'Deleted term %name.', array('%name' => $entity->name), WATCHDOG_NOTICE);
break;
case 'user':
watchdog('user', 'Deleted user: %name %email.', array('%name' => $entity->name, '%email' => '<' . $entity->mail . '>'), WATCHDOG_NOTICE);
break;
default:
watchdog('entity', 'Deleted @type %label.', array('@type' => $context['entity_type'], '%label' => entity_label($context['entity_type'], $entity)));
break;
}
}
}
function views_bulk_operations_delete_revision($entity, $context) {
@@ -1,24 +1,30 @@
<?php
/**
* @file VBO action to modify entity values (properties and fields).
* @file
* VBO action to modify entity values (properties and fields).
*/
// Specifies that all available values should be shown to the user for editing.
define('VBO_MODIFY_ACTION_ALL', '_all_');
/**
* Implements hook_action_info().
*/
function views_bulk_operations_modify_action_info() {
return array('views_bulk_operations_modify_action' => array(
'type' => 'entity',
'label' => t('Modify entity values'),
'behavior' => array('changes_property'),
// This action only works when invoked through VBO. That's why it's
// declared as non-configurable to prevent it from being shown in the
// "Create an advanced action" dropdown on admin/config/system/actions.
'configurable' => FALSE,
'vbo_configurable' => TRUE,
'triggers' => array('any'),
));
return array(
'views_bulk_operations_modify_action' => array(
'type' => 'entity',
'label' => t('Modify entity values'),
'behavior' => array('changes_property'),
// This action only works when invoked through VBO. That's why it's
// declared as non-configurable to prevent it from being shown in the
// "Create an advanced action" dropdown on admin/config/system/actions.
'configurable' => FALSE,
'vbo_configurable' => TRUE,
'triggers' => array('any'),
),
);
}
/**
@@ -28,7 +34,7 @@ function views_bulk_operations_modify_action_info() {
* replacing the existing values, or appending to them (based on user input).
*/
function views_bulk_operations_modify_action($entity, $context) {
list(,,$bundle_name) = entity_extract_ids($context['entity_type'], $entity);
list(,, $bundle_name) = entity_extract_ids($context['entity_type'], $entity);
// Handle Field API fields.
if (!empty($context['selected']['bundle_' . $bundle_name])) {
// The pseudo entity is cloned so that changes to it don't get carried
@@ -38,7 +44,7 @@ function views_bulk_operations_modify_action($entity, $context) {
// Get this field's language. We can just pull it from the pseudo entity
// as it was created using field_attach_form and entity_language so it's
// already been figured out if this field is translatable or not and
// applied the appropriate language code to the field
// applied the appropriate language code to the field.
$language = key($pseudo_entity->{$key});
// Replace any tokens that might exist in the field columns.
foreach ($pseudo_entity->{$key}[$language] as $delta => &$item) {
@@ -49,7 +55,7 @@ function views_bulk_operations_modify_action($entity, $context) {
}
}
if (in_array($key, $context['append']['bundle_' . $bundle_name]) && !empty($entity->$key)) {
if (in_array($key, $context['append']['bundle_' . $bundle_name]) && !empty($entity->{$key})) {
$entity->{$key}[$language] = array_merge($entity->{$key}[$language], $pseudo_entity->{$key}[$language]);
// Check if we breached cardinality, and notify the user.
@@ -58,9 +64,11 @@ function views_bulk_operations_modify_action($entity, $context) {
if ($field_info['cardinality'] != FIELD_CARDINALITY_UNLIMITED && $field_count > $field_info['cardinality']) {
$entity_label = entity_label($context['entity_type'], $entity);
$warning = t('Tried to set !field_count values for field !field_name that supports a maximum of !cardinality.',
array('!field_count' => $field_count,
'!field_name' => $field_info['field_name'],
'!cardinality' => $field_info['cardinality']));
array(
'!field_count' => $field_count,
'!field_name' => $field_info['field_name'],
'!cardinality' => $field_info['cardinality'],
));
drupal_set_message($warning, 'warning', FALSE);
}
@@ -76,25 +84,36 @@ function views_bulk_operations_modify_action($entity, $context) {
}
// Handle properties.
// Use the wrapper to set property values, since some properties need
// additional massaging by their setter callbacks.
// The wrapper will automatically modify $entity itself.
$wrapper = entity_metadata_wrapper($context['entity_type'], $entity);
// The default setting for 'revision' property (create new revisions) should
// be respected for nodes. This requires some special treatment.
if ($context['entity_type'] == 'node' && in_array('revision', variable_get('node_options_' . $bundle_name)) && !in_array('revision', $context['selected']['properties'])) {
$wrapper->revision->set(1);
}
if (!empty($context['selected']['properties'])) {
// Use the wrapper to set property values, since some properties need
// additional massaging by their setter callbacks.
// The wrapper will automatically modify $entity itself.
$wrapper = entity_metadata_wrapper($context['entity_type'], $entity);
foreach ($context['selected']['properties'] as $key) {
if (!$wrapper->{$key}->access('update')) {
// No access.
continue;
}
if (in_array($key, $context['append']['properties'])) {
$old_values = $wrapper->$key->value();
$wrapper->$key->set($context['properties'][$key]);
$old_values = $wrapper->{$key}->value();
$wrapper->{$key}->set($context['properties'][$key]);
$new_values = $wrapper->{$key}->value();
$all_values = array_merge($old_values, $new_values);
$wrapper->$key->set($all_values);
$wrapper->{$key}->set($all_values);
}
else {
$value = $context['properties'][$key];
if (is_string($value)) {
$value = token_replace($value, array($context['entity_type'] => $entity), array('sanitize' => FALSE));
}
$wrapper->$key->set($value);
$wrapper->{$key}->set($value);
}
}
}
@@ -108,7 +127,8 @@ function views_bulk_operations_modify_action($entity, $context) {
* entity bundle, as provided by field_attach_form().
*/
function views_bulk_operations_modify_action_form($context, &$form_state) {
// This action form uses admin-provided settings. If they were not set, pull the defaults now.
// This action form uses admin-provided settings. If they were not set, pull
// the defaults now.
if (!isset($context['settings'])) {
$context['settings'] = views_bulk_operations_modify_action_views_bulk_operations_form_options();
}
@@ -121,7 +141,8 @@ function views_bulk_operations_modify_action_form($context, &$form_state) {
// and filled with form data.
// After submit, the pseudo-entities get passed to the actual action
// (views_bulk_operations_modify_action()) which copies the data from the
// relevant pseudo-entity constructed here to the actual entity being modified.
// relevant pseudo-entity constructed here to the actual entity being
// modified.
$form_state['entities'] = array();
$info = entity_get_info($entity_type);
@@ -134,7 +155,7 @@ function views_bulk_operations_modify_action_form($context, &$form_state) {
if (!empty($properties)) {
$form['properties'] = array(
'#type' => 'fieldset',
'#title' => 'Properties',
'#title' => t('Properties'),
);
$form['properties']['show_value'] = array(
'#suffix' => '<div class="clearfix"></div>',
@@ -146,7 +167,16 @@ function views_bulk_operations_modify_action_form($context, &$form_state) {
'#title' => $property['label'],
);
$determined_type = ($property['type'] == 'boolean') ? 'checkbox' : 'textfield';
// According to _views_bulk_operations_modify_action_get_properties
// we have fixed list of supported types. Most of these types are string
// and only some of them has options list.
if (isset($property['options list'])) {
$determined_type = ($property['type'] == 'list') ? 'checkboxes' : 'select';
}
else {
$determined_type = ($property['type'] == 'boolean') ? 'checkbox' : 'textfield';
}
$form['properties'][$key] = array(
'#type' => $determined_type,
'#title' => $property['label'],
@@ -163,9 +193,9 @@ function views_bulk_operations_modify_action_form($context, &$form_state) {
$form['properties'][$key]['#maxlength'] = 255;
}
if (!empty($property['options list'])) {
if (!empty($property['options list']) && is_callable($property['options list'])) {
$form['properties'][$key]['#type'] = 'select';
$form['properties'][$key]['#options'] = $property['options list']($key, array());
$form['properties'][$key]['#options'] = call_user_func_array($property['options list'], array($key, array()));
if ($property['type'] == 'list') {
$form['properties'][$key]['#type'] = 'checkboxes';
@@ -184,7 +214,7 @@ function views_bulk_operations_modify_action_form($context, &$form_state) {
}
}
// Going to need this for multilingual nodes
// Going to need this for multilingual nodes.
global $language;
foreach ($bundles as $bundle_name => $bundle) {
$bundle_key = $info['entity keys']['bundle'];
@@ -197,8 +227,8 @@ function views_bulk_operations_modify_action_form($context, &$form_state) {
$entity = entity_create($context['entity_type'], $default_values);
$form_state['entities'][$bundle_name] = $entity;
// Show the more detailed label only if the entity type has multiple bundles.
// Otherwise, it would just be confusing.
// Show the more detailed label only if the entity type has multiple
// bundles. Otherwise, it would just be confusing.
if (count($info['bundles']) > 1) {
$label = t('Fields for @bundle_key @label', array('@bundle_key' => $bundle_key, '@label' => $bundle['label']));
}
@@ -298,7 +328,7 @@ function views_bulk_operations_modify_action_form($context, &$form_state) {
$token_type = str_replace('_', '-', $entity_type);
$form['tokens'] = array(
'#type' => 'fieldset',
'#title' => 'Available tokens',
'#title' => t('Available tokens'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 998,
@@ -375,7 +405,7 @@ function views_bulk_operations_modify_action_validate($form, &$form_state) {
$properties = _views_bulk_operations_modify_action_get_properties($form_state['entity_type']);
foreach ($form_state['selected']['properties'] as $key) {
$value = $form_state['values']['properties'][$key];
if (!$wrapper->$key->validate($value)) {
if (!$wrapper->{$key}->validate($value)) {
$label = $properties[$key]['label'];
form_set_error('properties][' . $key, t('%label contains an invalid value.', array('%label' => $label)));
}
@@ -412,9 +442,9 @@ function views_bulk_operations_modify_action_submit($form, $form_state) {
* Properties that can't be changed are entity keys, timestamps, and the ones
* without a setter callback.
*
* @param $entity_type
* @param string $entity_type
* The entity type whose properties will be fetched.
* @param $display_values
* @param array $display_values
* An optional, admin-provided list of properties and fields that should be
* displayed for editing, used to filter the returned list of properties.
*/
@@ -430,8 +460,17 @@ function _views_bulk_operations_modify_action_get_properties($entity_type, $disp
}
}
// List of supported types.
$supported_types = array('text', 'token', 'integer', 'decimal', 'date', 'duration',
'boolean', 'uri', 'list');
$supported_types = array(
'text',
'token',
'integer',
'decimal',
'date',
'duration',
'boolean',
'uri',
'list',
);
$property_info = entity_get_property_info($entity_type);
if (empty($property_info['properties'])) {
// Stop here if no properties were found.
@@ -479,9 +518,9 @@ function _views_bulk_operations_modify_action_get_properties($entity_type, $disp
* (through the action settings) then only bundles that have at least one field
* selected are returned.
*
* @param $entity_type
* @param string $entity_type
* The entity type whose bundles will be fetched.
* @param $context
* @param array $context
* The VBO context variable.
*/
function _views_bulk_operations_modify_action_get_bundles($entity_type, $context) {
@@ -589,8 +628,8 @@ function views_bulk_operations_modify_action_views_bulk_operations_form($options
}
foreach ($info['bundles'] as $bundle_name => $bundle) {
$bundle_key = $info['entity keys']['bundle'];
// Show the more detailed label only if the entity type has multiple bundles.
// Otherwise, it would just be confusing.
// Show the more detailed label only if the entity type has multiple
// bundles. Otherwise, it would just be confusing.
if (count($info['bundles']) > 1) {
$label = t('Fields for @bundle_key @label', array('@bundle_key' => $bundle_key, '@label' => $bundle['label']));
}
@@ -1,16 +1,19 @@
<?php
/**
* @file
* VBO action to cancel user accounts.
*/
* @file
* VBO action to cancel user accounts.
*/
function views_bulk_operations_user_cancel_action_info() {
return array('views_bulk_operations_user_cancel_action' => array(
'type' => 'user',
'label' => t('Cancel user account'),
'configurable' => TRUE,
'behavior' => array('deletes_property'),
));
return array(
'views_bulk_operations_user_cancel_action' => array(
'type' => 'user',
'label' => t('Cancel user account'),
'configurable' => TRUE,
'behavior' => array('deletes_property'),
'triggers' => array('any'),
),
);
}
function views_bulk_operations_user_cancel_action_form($context) {
@@ -74,7 +77,17 @@ function views_bulk_operations_user_cancel_action($account, $context) {
if (!empty($context['user_cancel_notify'])) {
_user_mail_notify('status_canceled', $account);
}
user_delete($account->uid);
// In cases when nodes are to be reassigned to UID 0, the user_delete must
// not run until *after* the user_cancel has been invoked, otherwise the
// nodes are deleted before they can be reassigned. Adding the user delete
// to the batch queue ensures things happen in the correct sequence.
$batch = array(
'operations' => array(
array('user_delete', array($account->uid)),
),
'file' => drupal_get_path('module', 'node') . '/node.admin.inc',
);
batch_set($batch);
watchdog('user', 'Deleted user: %name %email.', array('%name' => $account->name, '%email' => '<' . $account->mail . '>'), WATCHDOG_NOTICE);
break;
}
@@ -45,24 +45,19 @@ function views_bulk_operations_user_roles_action_submit($form, $form_state) {
);
}
function views_bulk_operations_user_roles_action(&$user, $context) {
$roles = $user->roles;
$selected = (is_array($context['add_roles']) ? $context['add_roles'] : array()) +
(is_array($context['remove_roles']) ? $context['remove_roles'] : array());
$result = db_query("SELECT rid, name FROM {role} WHERE rid IN (:selected)", array(':selected' => array_keys($selected)));
foreach ($result as $role) {
if (isset($context['add_roles'][$role->rid])) {
$add_roles[$role->rid] = $role->name;
}
if (isset($context['remove_roles'][$role->rid])) {
$remove_roles[$role->rid] = $role->name;
}
function views_bulk_operations_user_roles_action($user, $context) {
$wrapper = entity_metadata_wrapper('user', $user);
if (!$wrapper->roles->access("update")) {
// No access.
return;
}
if (!empty($add_roles)) {
$roles += $add_roles;
$roles = $wrapper->roles->value();
if (is_array($context['add_roles'])) {
$roles = array_merge($roles, $context['add_roles']);
}
if (!empty($remove_roles)) {
$roles = array_diff($roles, $remove_roles);
if (is_array($context['remove_roles'])) {
$roles = array_diff($roles, $context['remove_roles']);
}
user_save($user, array('roles' => $roles));
$wrapper->roles->set($roles);
$wrapper->save();
}
@@ -3,9 +3,8 @@ description = Provides permission-based access control for actions. Used by View
package = Administration
core = 7.x
; Information added by Drupal.org packaging script on 2013-12-23
version = "7.x-3.2"
; Information added by Drupal.org packaging script on 2018-05-08
version = "7.x-3.5"
core = "7.x"
project = "views_bulk_operations"
datestamp = "1387798183"
datestamp = "1525821486"
@@ -1,4 +1,5 @@
.vbo-select-all-markup, .vbo-table-select-all-markup {
.vbo-select-all-markup,
.vbo-table-select-all-markup {
display: none;
}
@@ -15,9 +16,10 @@
.views-table-row-select-all td {
text-align: center;
}
.vbo-table-select-all-pages, .vbo-table-select-this-page {
margin: 0 !important;
padding: 2px 5px !important;
.vbo-views-form .vbo-table-select-all-pages,
.vbo-views-form .vbo-table-select-this-page {
margin: 0;
padding: 2px 5px;
}
/* Generic "select all" */
@@ -30,6 +32,6 @@
margin-bottom: 0;
}
.vbo-fieldset-select-all div {
padding: 0 !important;
margin: 0 !important;
padding: 0;
margin: 0;
}
@@ -1,9 +1,17 @@
(function ($) {
// Polyfill for jQuery less than 1.6.
if (typeof $.fn.prop != 'function') {
jQuery.fn.extend({
prop: jQuery.fn.attr
});
}
Drupal.behaviors.vbo = {
attach: function(context) {
$('.vbo-views-form', context).each(function() {
Drupal.vbo.initTableBehaviors(this);
Drupal.vbo.initGenericBehaviors(this);
Drupal.vbo.toggleButtonsState(this);
});
}
}
@@ -30,9 +38,10 @@
$('.vbo-table-select-all', form).show();
// This is the "select all" checkbox in (each) table header.
$('.vbo-table-select-all', form).click(function() {
var table = $(this).closest('table')[0];
$('input[id^="edit-views-bulk-operations"]:not(:disabled)', table).attr('checked', this.checked);
$('input.vbo-table-select-all', form).click(function() {
var table = $(this).closest('table:not(.sticky-header)')[0];
$('.vbo-select:not(:disabled)', table).prop('checked', this.checked);
Drupal.vbo.toggleButtonsState(form);
// Toggle the visibility of the "select all" row (if any).
if (this.checked) {
@@ -46,21 +55,19 @@
});
// Set up the ability to click anywhere on the row to select it.
$('.views-table tbody tr', form).click(function(event) {
if (event.target.tagName.toLowerCase() != 'input' && event.target.tagName.toLowerCase() != 'a') {
$('input[id^="edit-views-bulk-operations"]:not(:disabled)', this).each(function() {
var checked = this.checked;
// trigger() toggles the checkmark *after* the event is set,
// whereas manually clicking the checkbox toggles it *beforehand*.
// that's why we manually set the checkmark first, then trigger the
// event (so that listeners get notified), then re-set the checkmark
// which the trigger will have toggled. yuck!
this.checked = !checked;
$(this).trigger('click');
this.checked = !checked;
});
}
});
if (Drupal.settings.vbo.row_clickable) {
$('.views-table tbody tr', form).click(function(event) {
var tagName = event.target.tagName.toLowerCase();
if (tagName != 'input' && tagName != 'a' && tagName != 'label') {
$('.vbo-select:not(:disabled)', this).each(function() {
// Always return true for radios, you cannot de-select a radio by clicking on it,
// it should be the same when clicking on a row.
this.checked = $(this).is(':radio') ? true : !this.checked;
$(this).trigger('change');
});
}
});
}
}
Drupal.vbo.tableSelectAllPages = function(form) {
@@ -81,35 +88,44 @@
$('.vbo-select-all-markup', form).show();
$('.vbo-select-this-page', form).click(function() {
$('input[id^="edit-views-bulk-operations"]', form).attr('checked', this.checked);
$('.vbo-select-all-pages', form).attr('checked', false);
$('.vbo-select', form).prop('checked', this.checked);
Drupal.vbo.toggleButtonsState(form);
$('.vbo-select-all-pages', form).prop('checked', false);
// Toggle the "select all" checkbox in grouped tables (if any).
$('.vbo-table-select-all', form).attr('checked', this.checked);
$('.vbo-table-select-all', form).prop('checked', this.checked);
});
$('.vbo-select-all-pages', form).click(function() {
$('input[id^="edit-views-bulk-operations"]', form).attr('checked', this.checked);
$('.vbo-select-this-page', form).attr('checked', false);
$('.vbo-select', form).prop('checked', this.checked);
Drupal.vbo.toggleButtonsState(form);
$('.vbo-select-this-page', form).prop('checked', false);
// Toggle the "select all" checkbox in grouped tables (if any).
$('.vbo-table-select-all', form).attr('checked', this.checked);
$('.vbo-table-select-all', form).prop('checked', this.checked);
// Modify the value of the hidden form field.
$('.select-all-rows', form).val(this.checked);
});
$('.vbo-select', form).click(function() {
// Toggle submit buttons' "disabled" states with the state of the operation
// selectbox.
$('select[name="operation"]', form).change(function () {
Drupal.vbo.toggleButtonsState(form);
});
// Handle a "change" event originating either from a row click or an actual checkbox click.
$('.vbo-select', form).change(function() {
// If a checkbox was deselected, uncheck any "select all" checkboxes.
if (!this.checked) {
$('.vbo-select-this-page', form).attr('checked', false);
$('.vbo-select-all-pages', form).attr('checked', false);
$('.vbo-select-this-page', form).prop('checked', false);
$('.vbo-select-all-pages', form).prop('checked', false);
// Modify the value of the hidden form field.
$('.select-all-rows', form).val('0')
var table = $(this).closest('table')[0];
if (table) {
// Uncheck the "select all" checkbox in the table header.
$('.vbo-table-select-all', table).attr('checked', false);
$('.vbo-table-select-all', table).prop('checked', false);
// If there's a "select all" row, hide it.
if ($('.vbo-table-select-this-page', table).length) {
@@ -119,7 +135,26 @@
}
}
}
Drupal.vbo.toggleButtonsState(form);
});
}
Drupal.vbo.toggleButtonsState = function(form) {
// If no rows are checked, disable any form submit actions.
var selectbox = $('select[name="operation"]', form);
var checkedCheckboxes = $('.vbo-select:checked', form);
// The .vbo-prevent-toggle CSS class is added to buttons to prevent toggling
// between disabled and enabled. For example the case of an 'add' button.
var buttons = $('[id^="edit-select"] [type="submit"]:not(.vbo-prevent-toggle)', form);
if (selectbox.length) {
var has_selection = checkedCheckboxes.length && selectbox.val() !== '0';
buttons.prop('disabled', !has_selection);
}
else {
buttons.prop('disabled', !checkedCheckboxes.length);
}
};
})(jQuery);
@@ -20,7 +20,7 @@ class ViewsBulkOperationsAction extends ViewsBulkOperationsBaseOperation {
*/
public function getAccessMask() {
// Assume edit by default.
if (!isset($this->operationInfo['behavior'])) {
if (empty($this->operationInfo['behavior'])) {
$this->operationInfo['behavior'] = array('changes_property');
}
@@ -128,7 +128,12 @@ class ViewsBulkOperationsAction extends ViewsBulkOperationsBaseOperation {
actions_list();
$submit_callback = $this->operationInfo['callback'] . '_submit';
$this->formOptions = $submit_callback($form, $form_state);
// If the return value from the callback is an options array, store it for
// later union onto the context.
$options = $submit_callback($form, $form_state);
if ($options && is_array($options)) {
$this->formOptions = $options;
}
}
/**
@@ -124,6 +124,8 @@ class ViewsBulkOperationsRulesComponent extends ViewsBulkOperationsBaseOperation
else {
$element = rules_action('component_' . $this->operationInfo['parameters']['component_key']);
}
$element->execute($data);
$wrapper_type = is_array($data) ? "list<{$this->entityType}>" : $this->entityType;
$wrapper = entity_metadata_wrapper($wrapper_type, $data);
$element->execute($wrapper);
}
}
@@ -6,7 +6,8 @@
function views_bulk_operations_views_data_alter(&$data) {
foreach (entity_get_info() as $entity_type => $info) {
if (isset($info['base table']) && isset($data[$info['base table']]['table'])) {
$data[$info['base table']]['views_bulk_operations'] = array(
$data[$info['base table']]['views_bulk_operations']['moved to'] = array('views_entity_' . $entity_type, 'views_bulk_operations');
$data['views_entity_' . $entity_type]['views_bulk_operations'] = array(
'title' => $data[$info['base table']]['table']['group'],
'group' => t('Bulk operations'),
'help' => t('Provide a checkbox to select the row for bulk operations.'),
@@ -6,7 +6,7 @@
* Implements the Views Form API.
*/
class views_bulk_operations_handler_field_operations extends views_handler_field {
class views_bulk_operations_handler_field_operations extends views_handler_field_entity {
var $revision = FALSE;
function init(&$view, &$options) {
@@ -46,6 +46,12 @@ class views_bulk_operations_handler_field_operations extends views_handler_field
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() {
@@ -55,6 +61,7 @@ class views_bulk_operations_handler_field_operations extends views_handler_field
'contains' => array(
'display_type' => array('default' => 0),
'enable_select_all_pages' => array('default' => TRUE),
'row_clickable' => array('default' => TRUE),
'force_single' => array('default' => FALSE),
'entity_load_capacity' => array('default' => 10),
'skip_batching' => array('default' => 0),
@@ -63,11 +70,26 @@ class views_bulk_operations_handler_field_operations extends views_handler_field
$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 -'),
@@ -107,6 +129,12 @@ class views_bulk_operations_handler_field_operations extends views_handler_field
'#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']['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'),
@@ -164,6 +192,14 @@ class views_bulk_operations_handler_field_operations extends views_handler_field
$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);
}
@@ -241,19 +277,21 @@ class views_bulk_operations_handler_field_operations extends views_handler_field
// 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) {
$entity_id = $this->get_value($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' => $entity_id,
'#return_value' => $id,
'#attributes' => array('class' => array('vbo-select')),
);
}
else {
$form[$this->options['id']][$row_index] = array(
'#type' => 'checkbox',
'#return_value' => $entity_id,
'#return_value' => $id,
'#default_value' => FALSE,
'#attributes' => array('class' => array('vbo-select')),
);
@@ -271,9 +309,12 @@ class views_bulk_operations_handler_field_operations extends views_handler_field
if (empty($options['selected'])) {
continue;
}
$operation = views_bulk_operations_get_operation($operation_id, $entity_type, $options);
if (!$operation || !$operation->access($user)) {
if (!$operation) {
continue;
}
$skip_permission_check = $operation->getAdminOption('skip_permission_check', FALSE);
if (!$operation->access($user) && !$skip_permission_check) {
continue;
}
$selected[$operation_id] = $operation;
@@ -296,29 +337,7 @@ class views_bulk_operations_handler_field_operations extends views_handler_field
* the entity type that VBO is operating on.
*/
public function get_entity_type() {
$base_table = $this->view->base_table;
// If the current field is under a relationship you can't be sure that the
// base table of the view is the base table of the current field.
// For example a field from a node author on a node view does have users as base table.
if (!empty($this->options['relationship']) && $this->options['relationship'] != 'none') {
$relationships = $this->view->display_handler->get_option('relationships');
$options = $relationships[$this->options['relationship']];
$data = views_fetch_data($options['table']);
$base_table = $data[$options['field']]['relationship']['base'];
}
// The base table is now known, use it to determine the entity type.
foreach (entity_get_info() as $entity_type => $info) {
if (isset($info['base table']) && $info['base table'] == $base_table) {
return $entity_type;
}
elseif (isset($info['revision table']) && $info['revision table'] == $base_table) {
$this->revision = TRUE;
return $entity_type;
}
}
// This should never happen.
_views_bulk_operations_report_error("Could not determine the entity type for VBO field on views base table %table", array('%table' => $base_table));
return FALSE;
return $this->entity_type;
}
}
@@ -154,7 +154,7 @@ function views_bulk_operations_drush_execute($vid = NULL, $operation_id = NULL)
$current = 1;
foreach ($view->result as $row_index => $result) {
$rows[$row_index] = array(
'entity_id' => $vbo->get_value($result),
'entity_id' => $result->{$vbo->real_field},
'views_row' => array(),
'position' => array(
'current' => $current++,
@@ -1,7 +1,7 @@
name = Views Bulk Operations
description = Provides a way of selecting multiple rows and applying operations to them.
dependencies[] = entity
dependencies[] = views
dependencies[] = views (>=3.12)
package = Views
core = 7.x
php = 5.2.9
@@ -9,9 +9,8 @@ php = 5.2.9
files[] = plugins/operation_types/base.class.php
files[] = views/views_bulk_operations_handler_field_operations.inc
; Information added by Drupal.org packaging script on 2013-12-23
version = "7.x-3.2"
; Information added by Drupal.org packaging script on 2018-05-08
version = "7.x-3.5"
core = "7.x"
project = "views_bulk_operations"
datestamp = "1387798183"
datestamp = "1525821486"
@@ -13,6 +13,7 @@ define('VBO_ACCESS_OP_DELETE', 0x08);
/**
* Implements hook_action_info().
*
* Registers custom VBO actions as Drupal actions.
*/
function views_bulk_operations_action_info() {
@@ -20,9 +21,14 @@ function views_bulk_operations_action_info() {
$files = views_bulk_operations_load_action_includes();
foreach ($files as $filename) {
$action_info_fn = 'views_bulk_operations_'. str_replace('.', '_', basename($filename, '.inc')).'_info';
$action_info = call_user_func($action_info_fn);
if (is_array($action_info)) {
$actions += $action_info;
if (is_callable($action_info_fn)) {
$action_info = call_user_func($action_info_fn);
if (is_array($action_info)) {
$actions += $action_info;
}
}
else {
watchdog('views bulk operations', 'views_bulk_operations_action_info() expects action filenames to have a matching valid callback function named: %function', array('%function' => $action_info_fn), WATCHDOG_WARNING);
}
}
@@ -41,21 +47,21 @@ function views_bulk_operations_load_action_includes() {
// The list of VBO actions is fairly static, so it's hardcoded for better
// performance (hitting the filesystem with file_scan_directory(), and then
// caching the result has its cost).
$path = drupal_get_path('module', 'views_bulk_operations') . '/actions/';
$files = array(
'archive.action.inc',
'argument_selector.action.inc',
'book.action.inc',
'delete.action.inc',
'modify.action.inc',
'script.action.inc',
'user_roles.action.inc',
'user_cancel.action.inc',
'archive.action',
'argument_selector.action',
'book.action',
'change_owner.action',
'delete.action',
'modify.action',
'script.action',
'user_roles.action',
'user_cancel.action',
);
if (!$loaded) {
foreach ($files as $file) {
include_once $path . $file;
module_load_include('inc', 'views_bulk_operations', 'actions/' . $file);
}
$loaded = TRUE;
}
@@ -76,8 +82,8 @@ function views_bulk_operations_load_action_includes() {
*/
function views_bulk_operations_cron() {
db_delete('queue')
->condition('name', db_like('views_bulk_operations_active_queue_'), 'LIKE')
->condition('created', REQUEST_TIME - 864000, '<')
->condition('name', db_like('views_bulk_operations_active_queue_') . '%', 'LIKE')
->condition('created', REQUEST_TIME - 86400, '<')
->execute();
}
@@ -190,7 +196,7 @@ function views_bulk_operations_get_operation_info($operation_id = NULL) {
$operations += $plugin['list callback']();
}
uasort($operations, create_function('$a, $b', 'return strcasecmp($a["label"], $b["label"]);'));
uasort($operations, '_views_bulk_operations_sort_operations_by_label');
}
if (!empty($operation_id)) {
@@ -201,6 +207,16 @@ function views_bulk_operations_get_operation_info($operation_id = NULL) {
}
}
/**
* Sort function used by uasort in views_bulk_operations_get_operation_info().
*
* A closure would be better suited for this, but closure support was added in
* PHP 5.3 and D7 supports 5.2.
*/
function _views_bulk_operations_sort_operations_by_label($a, $b) {
return strcasecmp($a['label'], $b['label']);
}
/**
* Returns an operation instance.
*
@@ -215,7 +231,12 @@ function views_bulk_operations_get_operation_info($operation_id = NULL) {
function views_bulk_operations_get_operation($operation_id, $entity_type, $options) {
$operations = &drupal_static(__FUNCTION__);
if (!isset($operations[$operation_id])) {
// Create a unique hash of the options.
$cid = md5(serialize($options));
// See if there's a cached copy of the operation, including entity type and
// options.
if (!isset($operations[$operation_id][$entity_type][$cid])) {
// Intentionally not using views_bulk_operations_get_operation_info() here
// since it's an expensive function that loads all the operations on the
// system, despite the fact that we might only need a few.
@@ -224,14 +245,14 @@ function views_bulk_operations_get_operation($operation_id, $entity_type, $optio
$operation_info = $plugin['list callback']($operation_id);
if ($operation_info) {
$operations[$operation_id] = new $plugin['handler']['class']($operation_id, $entity_type, $operation_info, $options);
$operations[$operation_id][$entity_type][$cid] = new $plugin['handler']['class']($operation_id, $entity_type, $operation_info, $options);
}
else {
$operations[$operation_id] = FALSE;
$operations[$operation_id][$entity_type][$cid] = FALSE;
}
}
return $operations[$operation_id];
return $operations[$operation_id][$entity_type][$cid];
}
/**
@@ -358,7 +379,7 @@ function views_bulk_operations_form_alter(&$form, &$form_state, $form_id) {
*/
function views_bulk_operations_views_post_build(&$view) {
$vbo = _views_bulk_operations_get_field($view);
if ($vbo && $vbo->get_selected_operations() < 1) {
if ($vbo && count($vbo->get_selected_operations()) < 1) {
$vbo->options['exclude'] = TRUE;
}
}
@@ -420,7 +441,7 @@ function theme_views_bulk_operations_select_all($variables) {
if ($enable_select_all_pages) {
$form['select_all']['or'] = array(
'#type' => 'markup',
'#markup' => '<em>OR</em>',
'#markup' => '<em>' . t('OR') . '</em>',
);
$form['select_all']['all_pages'] = array(
'#type' => 'checkbox',
@@ -443,6 +464,13 @@ function theme_views_bulk_operations_select_all($variables) {
*/
function views_bulk_operations_form($form, &$form_state, $vbo) {
$form['#attached']['js'][] = drupal_get_path('module', 'views_bulk_operations') . '/js/views_bulk_operations.js';
$form['#attached']['js'][] = array(
'data' => array('vbo' => array(
'row_clickable' => $vbo->get_vbo_option('row_clickable'),
)),
'type' => 'setting',
);
$form['#attached']['css'][] = drupal_get_path('module', 'views_bulk_operations') . '/css/views_bulk_operations.css';
// Wrap the form in a div with specific classes for JS targeting and theming.
$class = 'vbo-views-form';
@@ -511,7 +539,7 @@ function views_bulk_operations_form($form, &$form_state, $vbo) {
$enable_select_all_pages = FALSE;
// If the view is paginated, and "select all items on all pages" is
// enabled, tell that to the theme function.
if (count($vbo->view->result) != $vbo->view->total_rows && $vbo->get_vbo_option('enable_select_all_pages')) {
if (isset($vbo->view->total_rows) && count($vbo->view->result) != $vbo->view->total_rows && $vbo->get_vbo_option('enable_select_all_pages')) {
$enable_select_all_pages = TRUE;
}
$form['select_all_markup'] = array(
@@ -595,14 +623,23 @@ function views_bulk_operations_confirm_form($form, &$form_state, $view, $output)
$operation = $form_state['operation'];
$rows = $form_state['selection'];
$query = drupal_get_query_parameters($_GET, array('q'));
$title = t('Are you sure you want to perform %operation on the selected items?', array('%operation' => $operation->label()));
$form = confirm_form($form,
t('Are you sure you want to perform %operation on the selected items?', array('%operation' => $operation->label())),
$title,
array('path' => $view->get_url(), 'query' => $query),
theme('views_bulk_operations_confirmation', array('rows' => $rows, 'vbo' => $vbo, 'operation' => $operation, 'select_all_pages' => $form_state['select_all_pages']))
);
// Add VBO's submit handler to the Confirm button added by config_form().
$form['actions']['submit']['#submit'] = array('views_bulk_operations_form_submit');
// We can't set the View title here as $view is just a copy of the original,
// and our settings changes won't "stick" for the first page load of the
// confirmation form. We also can't just call drupal_set_title() directly
// because our title will be clobbered by the actual View title later. So
// let's tuck the title away in the form for use later.
// @see views_bulk_operations_preprocess_views_view()
$form['#vbo_confirm_form_title'] = $title;
return $form;
}
@@ -618,19 +655,42 @@ function theme_views_bulk_operations_confirmation($variables) {
// Load the entities from the current page, and show their titles.
$entities = _views_bulk_operations_entity_load($entity_type, array_values($rows), $vbo->revision);
foreach ($entities as $entity) {
$items[] = check_plain(_views_bulk_operations_entity_label($entity_type, $entity));
$items[] = check_plain(entity_label($entity_type, $entity));
}
// All rows on all pages have been selected, so show a count of additional items.
if ($select_all_pages) {
$more_count = $vbo->view->total_rows - count($vbo->view->result);
$items[] = t('...and <strong>!count</strong> more.', array('!count' => $more_count));
$items[] = t('...and %count more.', array('%count' => $more_count));
}
$count = format_plural(count($entities), 'item', '@count items');
$output = theme('item_list', array('items' => $items, 'title' => t('You selected the following <strong>!count</strong>:', array('!count' => $count))));
$output = theme('item_list', array('items' => $items, 'title' => t('You selected the following %count:', array('%count' => $count))));
return $output;
}
/**
* Implements hook_preprocess_page().
*
* Hide action links on the configure and confirm pages.
*/
function views_bulk_operations_preprocess_page(&$variables) {
if (isset($_POST['select_all'], $_POST['operation'])) {
$variables['action_links'] = array();
}
}
/**
* Implements hook_preprocess_views_view().
*/
function views_bulk_operations_preprocess_views_view($variables) {
// If we've stored a title for the confirmation form, retrieve it here and
// retitle the View.
// @see views_bulk_operations_confirm_form()
if (array_key_exists('rows', $variables) && is_array($variables['rows']) && array_key_exists('#vbo_confirm_form_title', $variables['rows'])) {
$variables['view']->set_title($variables['rows']['#vbo_confirm_form_title']);
}
}
/**
* Goes through the submitted values, and returns
* an array of selected rows, in the form of
@@ -798,7 +858,7 @@ function views_bulk_operations_execute($vbo, $operation, $selection, $select_all
// All items on all pages should be selected, add a batch job to gather
// and enqueue them.
if ($select_all_pages && $vbo->view->query->pager->has_more_records()) {
if ($select_all_pages && ($vbo->view->query->pager->has_more_records() || $vbo->view->query->pager->get_current_page() > 0)) {
$total_rows = $vbo->view->total_rows;
$batch['operations'][] = array(
@@ -864,14 +924,20 @@ function views_bulk_operations_adjust_selection($queue_name, $operation, $option
}
$vbo = _views_bulk_operations_get_field($view);
// Call views_handler_field_entity::pre_render() to get the entities.
$vbo->pre_render($view->result);
$rows = array();
foreach ($view->result as $row_index => $result) {
// Set the row index.
$view->row_index = $row_index;
$rows[$row_index] = array(
'entity_id' => $vbo->get_value($result),
'entity_id' => $vbo->get_value($result, $vbo->real_field),
'views_row' => array(),
'position' => array(
'current' => ++$context['sandbox']['progress'],
'total' => $view->total_rows,
'total' => $context['sandbox']['max'],
),
);
// Some operations require full selected rows.
@@ -1037,12 +1103,13 @@ function views_bulk_operations_queue_item_process($queue_item_data, &$log = NULL
}
// If the current entity can't be accessed, skip it and log a notice.
if (!_views_bulk_operations_entity_access($operation, $entity_type, $entity, $account)) {
$skip_permission_check = $operation->getAdminOption('skip_permission_check');
if (!$skip_permission_check && !_views_bulk_operations_entity_access($operation, $entity_type, $entity, $account)) {
$message = 'Skipped %operation on @type %title due to insufficient permissions.';
$arguments = array(
'%operation' => $operation->label(),
'@type' => $entity_type,
'%title' => _views_bulk_operations_entity_label($entity_type, $entity),
'%title' => entity_label($entity_type, $entity),
);
if ($log) {
@@ -1089,12 +1156,22 @@ function views_bulk_operations_direct_adjust(&$selection, $vbo) {
if ($field_name != $vbo->options['id']) {
unset($view->field[$field_name]);
}
else {
// Get hold of the new VBO field.
$new_vbo = $view->field[$field_name];
}
}
$view->execute($vbo->view->current_display);
// Call views_handler_field_entity::pre_render() to get the entities.
$new_vbo->pre_render($view->result);
$results = array();
foreach ($view->result as $row_index => $result) {
$results[$row_index] = $vbo->get_value($result);
// Set the row index.
$view->row_index = $row_index;
$results[$row_index] = $new_vbo->get_value($result, $new_vbo->real_field);
}
$selection = $results;
}
@@ -1122,13 +1199,14 @@ function views_bulk_operations_direct_process($operation, $rows, $options) {
}
$entities = _views_bulk_operations_entity_load($entity_type, $entity_ids, $options['revision']);
$skip_permission_check = $operation->getAdminOption('skip_permission_check');
// Filter out entities that can't be accessed.
foreach ($entities as $id => $entity) {
if (!_views_bulk_operations_entity_access($operation, $entity_type, $entity)) {
if (!$skip_permission_check && !_views_bulk_operations_entity_access($operation, $entity_type, $entity, $user)) {
$context['results']['log'][] = t('Skipped %operation on @type %title due to insufficient permissions.', array(
'%operation' => $operation->label(),
'@type' => $entity_type,
'%title' => _views_bulk_operations_entity_label($entity_type, $entity),
'%title' => entity_label($entity_type, $entity),
));
unset($entities[$id]);
}
@@ -1236,29 +1314,6 @@ function _views_bulk_operations_entity_load($entity_type, $ids, $revision = FALS
return $entities;
}
/**
* Label function for entities.
* Core entities don't declare the "label" key, so entity_label() fails,
* and a fallback is needed. This function provides that fallback.
*/
function _views_bulk_operations_entity_label($entity_type, $entity) {
$label = entity_label($entity_type, $entity);
if (!$label) {
$entity_info = entity_get_info($entity_type);
$id_key = $entity_info['entity keys']['id'];
// Many entity types (e.g. "user") have a name which fits the label perfectly.
if (isset($entity->name)) {
$label = $entity->name;
}
elseif (isset($entity->{$id_key})) {
// Fallback to the id key.
$label = $entity->{$id_key};
}
}
return $label;
}
/**
* Helper function to report an error.
*/
@@ -114,15 +114,25 @@ function views_bulk_operations_rules_action_info() {
function views_bulk_operations_views_list() {
$selectable_displays = array();
foreach (views_get_enabled_views() as $name => $base_view) {
$view = $base_view->clone_view();
foreach ($base_view->display as $display_name => $display) {
$view = $base_view->clone_view();
$view->build($display_name);
$vbo = _views_bulk_operations_get_field($view);
if ($vbo) {
$selectable_displays[$view->name . '|' . $display_name] = check_plain($view->human_name) . ' | ' . check_plain($display->display_title);
if (!$view->set_display($display_name)) {
continue;
}
// Initialize the style plugin and only continue to initialize handlers
// if the style uses fields.
if (!$view->init_style() || !$view->style_plugin->uses_fields()) {
continue;
}
$view->init_handlers($display_name);
if (_views_bulk_operations_get_field($view)) {
$selectable_displays[$view->name . '|' . $display_name] = check_plain($view->human_name . ' | ' . $display->display_title);
}
}
}
return $selectable_displays;
}
@@ -163,7 +173,11 @@ function views_bulk_operations_action_load_list($view, $args) {
$entity_type = $vbo->get_entity_type();
$entities = entity_metadata_wrapper("list<$entity_type>", array());
foreach ($vbo->view->result as $row_index => $result) {
$entities[] = entity_metadata_wrapper($entity_type, $vbo->get_value($result));
// Grab the entire entity if it's already loaded or fall back to the
// entity identifier.
$entity = $vbo->get_value($result);
$data = $entity ? $entity : $result->{$vbo->real_field};
$entities[] = entity_metadata_wrapper($entity_type, $data);
}
return array('entity_list' => $entities);