diff --git a/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php b/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php index cc1e56d..d807459 100644 --- a/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php +++ b/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php @@ -34,9 +34,9 @@ class DeleteMultiple extends ConfirmFormBase implements ControllerInterface { protected $tempStore; /** - * The entity manager. + * The node storage controller. * - * @var \Drupal\Core\Entity\EntityManager + * @var \Drupal\Core\Entity\EntityStorageControllerInterface */ protected $manager; @@ -50,7 +50,7 @@ class DeleteMultiple extends ConfirmFormBase implements ControllerInterface { */ public function __construct(TempStoreFactory $temp_store_factory, EntityManager $manager) { $this->tempStore = $temp_store_factory->get('node_multiple_delete_confirm'); - $this->manager = $manager; + $this->storageController = $manager->getStorageController('node'); } /** @@ -95,20 +95,17 @@ protected function getConfirmText() { * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { - global $user; - $this->nodes = $this->tempStore->get($user->uid); + $this->nodes = $this->tempStore->get($GLOBALS['user']->uid); if (empty($this->nodes)) { drupal_goto($this->getCancelPath()); } - foreach ($this->nodes as $nid => $node) { - $form['nodes'][$nid] = array( - '#type' => 'hidden', - '#value' => $nid, - '#prefix' => '
  • ', - '#suffix' => String::checkPlain($node->label()) . "
  • \n", - ); - } + $form['nodes'] = array( + '#theme' => 'item_list', + '#items' => array_map(function ($node) { + return String::checkPlain($node->label()); + }, $this->nodes), + ); return parent::buildForm($form, $form_state); } @@ -117,9 +114,8 @@ public function buildForm(array $form, array &$form_state) { */ public function submitForm(array &$form, array &$form_state) { if ($form_state['values']['confirm'] && !empty($this->nodes)) { - $this->manager->getStorageController('node')->delete($this->nodes); - global $user; - $this->tempStore->delete($user->uid); + $this->storageController->delete($this->nodes); + $this->tempStore->delete($GLOBALS['user']->uid); $count = count($this->nodes); watchdog('content', 'Deleted @count posts.', array('@count' => $count)); drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.')); @@ -127,4 +123,14 @@ public function submitForm(array &$form, array &$form_state) { $form_state['redirect'] = 'admin/content'; } + /** + * Stores an array of nodes in temp store. + * + * @param array $nodes + * An array of node objects. + */ + public static function storeNodes(array $nodes) { + \Drupal::service('user.tempstore')->get('node_multiple_delete_confirm')->set($GLOBALS['user']->uid, $nodes); + } + } 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 index 5986cd1..be18eef 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/field/NodeBulkForm.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/field/NodeBulkForm.php @@ -32,7 +32,9 @@ protected function getBulkOptions() { * {@inheritdoc} */ public function views_form_validate(&$form, &$form_state) { - $selected = array_filter($form_state['values'][$this->options['id']]); + if (isset($form_state['values'][$this->options['id']])) { + $selected = array_filter($form_state['values'][$this->options['id']]); + } if (empty($selected)) { form_set_error('', t('No items selected.')); } @@ -56,20 +58,18 @@ public function views_form_submit(&$form, &$form_state) { $operation = $operations[$form_state['values']['action']]; // Filter out unchecked nodes $nodes = array_filter($nodes); - if ($function = $operation['callback']) { - // Add in callback arguments if present. - if (isset($operation['callback arguments'])) { - $args = array_merge(array($nodes), $operation['callback arguments']); - } - else { - $args = array($nodes); - } - call_user_func_array($function, $args); - Cache::invalidateTags(array('content' => TRUE)); + // Add in callback arguments if present. + if (isset($operation['callback arguments'])) { + $args = array_merge(array($nodes), $operation['callback arguments']); + } + else { + $args = array($nodes); + } + call_user_func_array($operation['callback'], $args); + Cache::invalidateTags(array('content' => TRUE)); - if (isset($operation['redirect'])) { - $form_state['redirect'] = $operation['redirect']; - } + if (isset($operation['redirect'])) { + $form_state['redirect'] = $operation['redirect']; } } } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAdminTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAdminTest.php index 15db2b4..ece54f7 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAdminTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAdminTest.php @@ -48,7 +48,7 @@ function testContentAdminSort() { $this->drupalLogin($this->admin_user); // Create nodes that have different node.changed values. - \Drupal::state()->set('node_test.storage_controller', TRUE); + $this->container->get('state')->set('node_test.storage_controller', TRUE); module_enable(array('node_test')); $changed = REQUEST_TIME; foreach (array('dd', 'aa', 'DD', 'bb', 'cc', 'CC', 'AA', 'BB') as $prefix) { diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc index e931dd1..a9700b0 100644 --- a/core/modules/node/node.admin.inc +++ b/core/modules/node/node.admin.inc @@ -6,6 +6,7 @@ */ use Drupal\Core\Database\Query\SelectInterface; +use Drupal\node\NodeInterface; /** * Page callback: Form constructor for the permission rebuild confirmation form. @@ -67,7 +68,7 @@ function node_node_operations() { ), 'delete' => array( 'label' => t('Delete selected content'), - 'callback' => 'node_multiple_delete_confirm', + 'callback' => array('\Drupal\node\Form\DeleteMultiple', 'storeNodes'), 'redirect' => 'admin/content/node/delete', ), ); @@ -90,7 +91,7 @@ function node_node_operations() { * (optional) TRUE if $nodes contains an array of node IDs to be loaded, FALSE * if it contains fully loaded nodes. Defaults to FALSE. */ -function node_mass_update($nodes, $updates, $load = FALSE) { +function node_mass_update(array $nodes, array $updates, $load = FALSE) { // We use batch processing to prevent timeout when updating a large number // of nodes. if (count($nodes) > 10) { @@ -124,17 +125,17 @@ function node_mass_update($nodes, $updates, $load = FALSE) { /** * Updates individual nodes when fewer than 10 are queued. * - * @param $node + * @param \Drupal\node\NodeInterface $node * A node to update. - * @param $updates + * @param array $updates * Associative array of updates. * - * @return object + * @return \Drupal\node\NodeInterface * An updated node object. * * @see node_mass_update() */ -function _node_mass_update_helper($node, $updates) { +function _node_mass_update_helper(NodeInterface $node, array $updates) { // For efficiency manually save the original node before applying any changes. $node->original = clone $node; foreach ($updates as $name => $value) { @@ -157,7 +158,7 @@ function _node_mass_update_helper($node, $updates) { * @param array $context * An array of contextual key/values. */ -function _node_mass_update_batch_process($nodes, $updates, $load, &$context) { +function _node_mass_update_batch_process(array $nodes, array $updates, $load, array &$context) { if (!isset($context['sandbox']['progress'])) { $context['sandbox']['progress'] = 0; $context['sandbox']['max'] = count($nodes); @@ -214,8 +215,6 @@ function _node_mass_update_batch_finished($success, $results, $operations) { /** * Returns the admin form object to node_admin_content(). * - * @see node_multiple_delete_confirm() - * * @ingroup forms */ function node_admin_nodes() { @@ -364,13 +363,3 @@ function node_admin_nodes() { $build['pager'] = array('#theme' => 'pager'); return $build; } - -/** - * Multiple node deletion confirmation form for node_admin_content(). - * - * @see node_admin_nodes() - */ -function node_multiple_delete_confirm($nodes) { - global $user; - Drupal::service('user.tempstore')->get('node_multiple_delete_confirm')->set($user->uid, $nodes); -}