diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/field/NodeBulkForm.php b/core/modules/node/lib/Drupal/node/Plugin/views/field/NodeBulkForm.php new file mode 100644 index 0000000..15dc29a --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/NodeBulkForm.php @@ -0,0 +1,58 @@ +options['id']]); + $nodes = array(); + foreach (array_intersect_key($this->view->result, $selected) as $node) { + $nid = $this->get_entity($node)->id(); + $nodes[$nid] = $nid; + } + + $submit = array( + 'values' => array( + 'operation' => $form_state['values']['action'], + 'nodes' => $nodes, + ), + ); + // @todo Move the submit function code here. + module_load_include('inc', 'node', 'node.admin'); + node_admin_nodes_submit($form, $submit); + } + } + +} diff --git a/core/modules/node/lib/Drupal/node/Tests/Views/BulkFormTest.php b/core/modules/node/lib/Drupal/node/Tests/Views/BulkFormTest.php new file mode 100644 index 0000000..128cb4f --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Tests/Views/BulkFormTest.php @@ -0,0 +1,55 @@ + 'Node: Bulk form', + 'description' => 'Tests a node bulk form.', + 'group' => 'Views Modules', + ); + } + + /** + * Tests the node bulk form. + */ + public function testBulkForm() { + $this->drupalLogin($this->drupalCreateUser(array('administer nodes'))); + $node = $this->drupalCreateNode(); + + $this->drupalGet('test-node-bulk-form'); + $elements = $this->xpath('//select[@id="edit-action"]//option'); + $this->assertIdentical(count($elements), 7, 'All node operations are found.'); + + // Block a node using the bulk form. + $this->assertTrue($node->status); + $edit = array( + 'node_bulk_form[0]' => TRUE, + 'action' => 'unpublish', + ); + $this->drupalPost(NULL, $edit, t('Apply')); + // Re-load the node and check their status. + $node = entity_load('node', $node->id()); + $this->assertFalse($node->status); + } + +} diff --git a/core/modules/node/node.views.inc b/core/modules/node/node.views.inc index 2e8ab14..bd44ba1 100644 --- a/core/modules/node/node.views.inc +++ b/core/modules/node/node.views.inc @@ -226,6 +226,14 @@ function node_views_data() { ); } + $data['node']['node_bulk_form'] = array( + 'title' => t('Node operations bulk form'), + 'help' => t('Add a form element that lets you run operations on multiple nodes.'), + 'field' => array( + 'id' => 'node_bulk_form', + ), + ); + // Define some fields based upon views_handler_field_entity in the entity // table so they can be re-used with other query backends. // @see views_handler_field_entity diff --git a/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_bulk_form.yml b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_bulk_form.yml new file mode 100644 index 0000000..8641117 --- /dev/null +++ b/core/modules/node/tests/modules/node_test_views/test_views/views.view.test_node_bulk_form.yml @@ -0,0 +1,42 @@ +base_field: nid +base_table: node +core: 8.x +description: '' +disabled: '0' +display: + default: + display_plugin: default + id: default + display_title: Master + position: '' + display_options: + style: + type: table + row: + type: fields + fields: + node_bulk_form: + id: node_bulk_form + table: node + field: node_bulk_form + title: + id: title + table: node + field: title + sorts: + nid: + id: nid + table: node + field: nid + order: ASC + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: '' + display_options: + path: test-node-bulk-form +human_name: '' +module: views +id: test_node_bulk_form +tag: ''