diff --git a/core/modules/comment/comment.routing.yml b/core/modules/comment/comment.routing.yml index 6273eb7..29bbc4b 100644 --- a/core/modules/comment/comment.routing.yml +++ b/core/modules/comment/comment.routing.yml @@ -2,7 +2,7 @@ comment.admin: path: '/admin/content/comment' defaults: _title: 'Comments' - _content: '\Drupal\comment\Controller\AdminController::adminPage' + _form: 'Drupal\comment\Form\CommentAdminOverview' type: 'new' requirements: _permission: 'administer comments' @@ -11,7 +11,7 @@ comment.admin_approval: path: '/admin/content/comment/approval' defaults: _title: 'Unapproved comments' - _content: '\Drupal\comment\Controller\AdminController::adminPage' + _form: 'Drupal\comment\Form\CommentAdminOverview' type: 'approval' requirements: _permission: 'administer comments' @@ -50,6 +50,14 @@ comment.confirm_delete: requirements: _entity_access: 'comment.delete' +comment.multiple_delete_confirm: + path: '/admin/content/comment/delete' + defaults: + _title: 'Delete' + _form: '\Drupal\comment\Form\ConfirmDeleteMultiple' + requirements: + _permission: 'administer comments' + comment.reply: path: '/comment/reply/{entity_type}/{entity_id}/{field_name}/{pid}' defaults: diff --git a/core/modules/comment/comment.views.inc b/core/modules/comment/comment.views.inc index 2f37b53..8c99e03 100644 --- a/core/modules/comment/comment.views.inc +++ b/core/modules/comment/comment.views.inc @@ -426,11 +426,11 @@ function comment_views_data() { ); } $data['comment']['comment_bulk_form'] = array( - 'title' => t('Comment operations bulk form'), - 'help' => t('Add a form element that lets you run operations on multiple comments.'), - 'field' => array( - 'id' => 'comment_bulk_form', - ), + 'title' => t('Comment operations bulk form'), + 'help' => t('Add a form element that lets you run operations on multiple comments.'), + 'field' => array( + 'id' => 'comment_bulk_form', + ), ); diff --git a/core/modules/comment/config/system.action.comment_delete_action.yml b/core/modules/comment/config/system.action.comment_delete_action.yml index aa42f70..90f85f2 100644 --- a/core/modules/comment/config/system.action.comment_delete_action.yml +++ b/core/modules/comment/config/system.action.comment_delete_action.yml @@ -1,6 +1,8 @@ id: comment_delete_action label: 'Delete comment' +uuid: jibran95-m4d3-th15-uu1d-f0rc0mm3n752 status: true langcode: en type: comment plugin: comment_delete_action +configuration: { } diff --git a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php index 7378585..a6156a4 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php @@ -36,11 +36,17 @@ class AdminController extends ControllerBase implements ContainerInjectionInterf protected $commentManager; /** - * The form builder. + * Constructs an AdminController object. * - * @var \Drupal\Core\Form\FormBuilderInterface + * @param \Drupal\field\FieldInfo $field_info + * The field info service. + * @param \Drupal\comment\CommentManagerInterface $comment_manager + * The comment manager service. */ - protected $formBuilder; + public function __construct(FieldInfo $field_info, CommentManagerInterface $comment_manager) { + $this->fieldInfo = $field_info; + $this->commentManager = $comment_manager; + } /** * {@inheritdoc} @@ -48,28 +54,11 @@ class AdminController extends ControllerBase implements ContainerInjectionInterf public static function create(ContainerInterface $container) { return new static( $container->get('field.info'), - $container->get('comment.manager'), - $container->get('form_builder') + $container->get('comment.manager') ); } /** - * Constructs an AdminController object. - * - * @param \Drupal\field\FieldInfo $field_info - * The field info service. - * @param \Drupal\comment\CommentManagerInterface $comment_manager - * The comment manager service. - * @param \Drupal\Core\Form\FormBuilderInterface $form_builder - * The form builder. - */ - public function __construct(FieldInfo $field_info, CommentManagerInterface $comment_manager, FormBuilderInterface $form_builder) { - $this->fieldInfo = $field_info; - $this->commentManager = $comment_manager; - $this->formBuilder = $form_builder; - } - - /** * Returns an overview of comment fields in use on the site. * * @return array @@ -238,25 +227,4 @@ public function bundleTitle($commented_entity_type, $field_name) { return $this->commentManager->getFieldUIPageTitle($commented_entity_type, $field_name); } - /** - * Presents an administrative comment listing. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The request of the page. - * @param string $type - * The type of the overview form ('approval' or 'new') default to 'new'. - * - * @return array - * Then comment multiple delete confirmation form or the comments overview - * administration form. - */ - public function adminPage(Request $request, $type = 'new') { - if ($request->request->get('operation') == 'delete' && $request->request->get('comments')) { - return $this->formBuilder->getForm('\Drupal\comment\Form\ConfirmDeleteMultiple', $request); - } - else { - return $this->formBuilder->getForm('\Drupal\comment\Form\CommentAdminOverview', $type); - } - } - } diff --git a/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php index 07c6d54..272cfea 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php +++ b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php @@ -9,6 +9,7 @@ use Drupal\comment\CommentInterface; use Drupal\comment\CommentStorageControllerInterface; +use Drupal\user\TempStoreFactory; use Drupal\Component\Utility\Unicode; use Drupal\Core\Cache\Cache; use Drupal\Core\Datetime\Date; @@ -59,6 +60,13 @@ class CommentAdminOverview extends FormBase { protected $moduleHandler; /** + * The tempstore factory. + * + * @var \Drupal\user\TempStoreFactory + */ + protected $tempStoreFactory; + + /** * Creates a CommentAdminOverview form. * * @param \Drupal\Core\Entity\EntityManager $entity_manager @@ -71,13 +79,16 @@ class CommentAdminOverview extends FormBase { * The date service. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. + * @param \Drupal\user\TempStoreFactory $temp_store_factory + * The tempstore factory. */ - public function __construct(EntityManager $entity_manager, CommentStorageControllerInterface $comment_storage, QueryFactory $entity_query, Date $date, ModuleHandlerInterface $module_handler) { + public function __construct(EntityManager $entity_manager, CommentStorageControllerInterface $comment_storage, QueryFactory $entity_query, Date $date, ModuleHandlerInterface $module_handler, TempStoreFactory $temp_store_factory) { $this->entityManager = $entity_manager; $this->commentStorage = $comment_storage; $this->entityQuery = $entity_query; $this->date = $date; $this->moduleHandler = $module_handler; + $this->tempStoreFactory = $temp_store_factory; } /** @@ -89,7 +100,8 @@ public static function create(ContainerInterface $container) { $container->get('entity.manager')->getStorageController('comment'), $container->get('entity.query'), $container->get('date'), - $container->get('module_handler') + $container->get('module_handler'), + $container->get('user.tempstore') ); } @@ -280,26 +292,33 @@ public function validateForm(array &$form, array &$form_state) { public function submitForm(array &$form, array &$form_state) { $operation = $form_state['values']['operation']; $cids = $form_state['values']['comments']; - - foreach ($cids as $cid) { - // Delete operation handled in \Drupal\comment\Form\ConfirmDeleteMultiple - // see \Drupal\comment\Controller\AdminController::adminPage(). - if ($operation == 'unpublish') { - $comment = $this->commentStorage->load($cid); - $comment->status->value = CommentInterface::NOT_PUBLISHED; - $comment->save(); - } - elseif ($operation == 'publish') { - $comment = $this->commentStorage->load($cid); - $comment->status->value = CommentInterface::PUBLISHED; - $comment->save(); + if ($operation != 'delete') { + foreach ($cids as $cid) { + if ($operation == 'unpublish') { + $comment = $this->commentStorage->load($cid); + $comment->status->value = CommentInterface::NOT_PUBLISHED; + $comment->save(); + } + elseif ($operation == 'publish') { + $comment = $this->commentStorage->load($cid); + $comment->status->value = CommentInterface::PUBLISHED; + $comment->save(); + } } + drupal_set_message($this->t('The update has been performed.')); + $form_state['redirect_route'] = array( + 'route_name' => 'comment.admin', + ); + Cache::invalidateTags(array('content' => TRUE)); + } + else { + $this->tempStoreFactory + ->get('comment_multiple_delete_confirm') + ->set(\Drupal::currentUser()->id(), $this->commentStorage->loadMultiple($cids)); + $form_state['redirect_route'] = array( + 'route_name' => 'comment.multiple_delete_confirm', + ); } - drupal_set_message($this->t('The update has been performed.')); - $form_state['redirect_route'] = array( - 'route_name' => 'comment.admin', - ); - Cache::invalidateTags(array('content' => TRUE)); } } diff --git a/core/modules/comment/lib/Drupal/comment/Form/ConfirmDeleteMultiple.php b/core/modules/comment/lib/Drupal/comment/Form/ConfirmDeleteMultiple.php index b791b30..bb6fd57 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/ConfirmDeleteMultiple.php +++ b/core/modules/comment/lib/Drupal/comment/Form/ConfirmDeleteMultiple.php @@ -8,10 +8,12 @@ namespace Drupal\comment\Form; use Drupal\comment\CommentStorageControllerInterface; +use Drupal\user\TempStoreFactory; use Drupal\Component\Utility\String; use Drupal\Core\Cache\Cache; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Form\ConfirmFormBase; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -20,6 +22,13 @@ class ConfirmDeleteMultiple extends ConfirmFormBase implements ContainerInjectionInterface { /** + * The tempstore factory. + * + * @var \Drupal\user\TempStoreFactory + */ + protected $tempStoreFactory; + + /** * The comment storage. * * @var \Drupal\comment\CommentStorageControllerInterface @@ -38,9 +47,12 @@ class ConfirmDeleteMultiple extends ConfirmFormBase implements ContainerInjectio * * @param \Drupal\comment\CommentStorageControllerInterface $comment_storage * The comment storage. + * @param \Drupal\user\TempStoreFactory $temp_store_factory + * The tempstore factory. */ - public function __construct(CommentStorageControllerInterface $comment_storage) { + public function __construct(CommentStorageControllerInterface $comment_storage, TempStoreFactory $temp_store_factory) { $this->commentStorage = $comment_storage; + $this->tempStoreFactory = $temp_store_factory; } /** @@ -48,7 +60,8 @@ public function __construct(CommentStorageControllerInterface $comment_storage) */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager')->getStorageController('comment') + $container->get('entity.manager')->getStorageController('comment'), + $container->get('user.tempstore') ); } @@ -63,7 +76,7 @@ public function getFormId() { * {@inheritdoc} */ public function getQuestion() { - return $this->t('Are you sure you want to delete these comments and all their children?'); + return $this->translationManager()->formatPlural(count($this->comments), 'Are you sure you want to delete this comment and all its children?', 'Are you sure you want to delete these comments and all their children?'); } /** @@ -79,23 +92,24 @@ public function getCancelRoute() { * {@inheritdoc} */ public function getConfirmText() { - return $this->t('Delete comments'); + return $this->t('Delete'); } /** * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { - $edit = $form_state['input']; + $this->comments = $this->tempStoreFactory->get('comment_multiple_delete_confirm')->get(\Drupal::currentUser()->id()); + if (empty($this->comments)) { + return new RedirectResponse($this->urlGenerator()->generate('comment.admin')); + } $form['comments'] = array( '#prefix' => '', '#tree' => TRUE, ); - // array_filter() returns only elements with actual values. - $comment_counter = 0; - $this->comments = $this->commentStorage->loadMultiple(array_keys(array_filter($edit['comments']))); + foreach ($this->comments as $comment) { $cid = $comment->id(); $form['comments'][$cid] = array( @@ -104,15 +118,9 @@ public function buildForm(array $form, array &$form_state) { '#prefix' => '
  • ', '#suffix' => String::checkPlain($comment->label()) . '
  • ' ); - $comment_counter++; } $form['operation'] = array('#type' => 'hidden', '#value' => 'delete'); - if (!$comment_counter) { - drupal_set_message($this->t('There do not appear to be any comments to delete, or your selected comment was deleted by another administrator.')); - $form_state['redirect_route']['route_name'] = 'comment.admin'; - } - return parent::buildForm($form, $form_state); } @@ -120,12 +128,13 @@ public function buildForm(array $form, array &$form_state) { * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - if ($form_state['values']['confirm']) { + if ($form_state['values']['confirm'] && !empty($this->comments)) { $this->commentStorage->delete($this->comments); - Cache::invalidateTags(array('content' => TRUE)); - $count = count($form_state['values']['comments']); + $this->tempStoreFactory->get('comment_multiple_delete_confirm')->delete(\Drupal::currentUser()->id()); + $count = count($this->comments); watchdog('content', 'Deleted @count comments.', array('@count' => $count)); - drupal_set_message(format_plural($count, 'Deleted 1 comment.', 'Deleted @count comments.')); + drupal_set_message($this->translationManager()->formatPlural($count, 'Deleted 1 comment.', 'Deleted @count comments.')); + Cache::invalidateTags(array('content' => TRUE)); } $form_state['redirect_route']['route_name'] = 'comment.admin'; }