Commit 13b7a73c authored by catch's avatar catch

Issue #1845840 by wuinfo, sun, IshaDakota, dawehner: Tweak the UI/UX and...

Issue #1845840 by wuinfo, sun, IshaDakota, dawehner: Tweak the UI/UX and accessibility of the views bulk operations interface.
parent c76c95a9
......@@ -15,13 +15,12 @@
*/
function action_views_data() {
$data['views']['action_bulk_form'] = array(
'title' => t('Actions bulk form'),
'help' => t('Add a form element that lets you apply actions to multiple items.'),
'title' => t('Bulk update'),
'help' => t('Allows users to apply an action to one or more items.'),
'field' => array(
'id' => 'action_bulk_form',
),
);
return $data;
}
......@@ -29,15 +28,13 @@ function action_views_data() {
* Implements hook_views_form_substitutions().
*/
function action_views_form_substitutions() {
// Views check_plains the column label, so by doing it matches for the
// replacement.
// Views check_plain()s the column label, so we need to match that.
$select_all_placeholder = check_plain('<!--action-bulk-form-select-all-->');
$select_all = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
'#attributes' => array('class' => array('action-table-select-all')),
);
return array(
$select_all_placeholder => drupal_render($select_all),
);
......
......@@ -51,21 +51,22 @@ public function views_form(&$form, &$form_state) {
$form['#attached']['library'][] = array('system', 'drupal.tableselect');
// Render checkboxes for all rows.
$form[$this->options['id']]['#tree'] = TRUE;
foreach ($this->view->result as $row_index => $row) {
$entity_id = $this->get_value($row);
$form[$this->options['id']][$row_index] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
// We are not able to determine a main "title" for each row, so we can
// only output a generic label.
'#title' => t('Update this item'),
'#title_display' => 'invisible',
'#default_value' => !empty($form_state['values'][$this->options['id']][$row_index]) ? 1 : NULL,
);
}
$form[$this->options['id']]['#tree'] = TRUE;
// Get all available actions.
$actions = action_get_all_actions();
$entity_type = $this->getEntityType();
// Filter actions by the entity type and build options for the form.
// Filter actions by entity type and build select options.
$actions = array_filter($actions, function($action) use ($entity_type) {
return $action['type'] == $entity_type && empty($action['configurable']);
});
......@@ -73,22 +74,28 @@ public function views_form(&$form, &$form_state) {
return $action['label'];
}, $actions);
$form['action'] = array(
// Replace the form submit button label.
$form['actions']['submit']['#value'] = t('Apply');
// Ensure a consistent container for filters/operations in the view header.
$form['header'] = array(
'#type' => 'container',
'#weight' => -100,
);
// Build the bulk operations action widget for the header.
// Allow themes to apply .container-inline on this separate container.
$form['header'][$this->options['id']] = array(
'#type' => 'container',
);
$form['header'][$this->options['id']]['action'] = array(
'#type' => 'select',
'#title' => t('Action'),
'#title' => t('With selection'),
'#options' => $options,
'#description' => t('Select the action you want to execute on the content entitites.'),
);
// Move the submit button beside the selection.
$form['actions']['#weight'] = 1;
// Replace the text with Update.
$form['actions']['submit']['#value'] = t('Update');
// Put the submit button both at the top and bottom.
$form['actions_bottom'] = $form['actions'];
$form['actions_bottom']['#weight'] = 100;
// Duplicate the form actions into the action container in the header.
$form['header'][$this->options['id']]['actions'] = $form['actions'];
}
/**
......@@ -113,7 +120,9 @@ public function views_form_submit(&$form, &$form_state) {
}
if ($count) {
drupal_set_message(t('%action action performed on %count item(s).', array('%action' => $action->label, '%count' => $count)));
drupal_set_message(format_plural($count, '%action was applied to @count item.', '%action was applied to @count items.', array(
'%action' => $action->label,
)));
}
}
}
......
......@@ -53,23 +53,23 @@ public function testBulkForm() {
// Set all nodes to sticky and check that.
$edit += array('action' => 'node_make_sticky_action');
$this->drupalPost(NULL, $edit, t('Update'));
$this->drupalPost(NULL, $edit, t('Apply'));
foreach ($nodes as $node) {
$changed_node = node_load($node->id());
$this->assertTrue($changed_node->sticky, format_string('Node @nid got marked as sticky.', array('@nid' => $node->id())));
}
$this->assertText('Make content sticky action performed on 10 item(s).');
$this->assertText('Make content sticky was applied to 10 items.');
// Unpublish just one node.
$node = node_load($nodes[0]->id());
$this->assertTrue($node->status, 'The node is published.');
$edit = array('bulk_form[0]' => TRUE, 'action' => 'node_unpublish_action');
$this->drupalPost(NULL, $edit, t('Update'));
$this->drupalPost(NULL, $edit, t('Apply'));
$this->assertText('Unpublish content action performed on 1 item(s).');
$this->assertText('Unpublish content was applied to 1 item.');
// Load the node again.
$node = node_load($node->id(), TRUE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment