diff --git a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php index 7693b54..6c8afca 100644 --- a/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php +++ b/core/modules/comment/lib/Drupal/comment/Controller/AdminController.php @@ -7,13 +7,12 @@ namespace Drupal\comment\Controller; -use Drupal\comment\Form\ConfirmDeleteMultiple; -use Drupal\comment\Form\CommentAdminOverview; use Drupal\comment\CommentManagerInterface; use Drupal\field\FieldInfo; use Drupal\Component\Utility\String; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\Form\FormBuilderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -37,12 +36,20 @@ class AdminController extends ControllerBase implements ContainerInjectionInterf protected $commentManager; /** + * The form builder. + * + * @var \Drupal\Core\Form\FormBuilderInterface + */ + protected $formBuilder; + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('field.info'), - $container->get('comment.manager') + $container->get('comment.manager'), + $container->get('form_builder') ); } @@ -53,10 +60,13 @@ public static function create(ContainerInterface $container) { * 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) { + public function __construct(FieldInfo $field_info, CommentManagerInterface $comment_manager, FormBuilderInterface $form_builder) { $this->fieldInfo = $field_info; $this->commentManager = $comment_manager; + $this->formBuilder = $form_builder; } /** @@ -241,13 +251,11 @@ public function bundleTitle($commented_entity_type, $field_name) { * administration form. */ public function adminPage(Request $request, $type = 'new') { - $edit = $request->request->all(); - - if (isset($edit['operation']) && ($edit['operation'] == 'delete') && isset($edit['comments']) && $edit['comments']) { - return drupal_get_form(ConfirmDeleteMultiple::create($this->container()), $request); + if ($request->request->get('operation') == 'delete' && $request->request->get('comments')) { + return $this->formBuilder->getForm('\Drupal\comment\Form\ConfirmDeleteMultiple', $request); } else { - return drupal_get_form(CommentAdminOverview::create($this->container()), $type); + 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 1061059..19cc65a 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php +++ b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php @@ -278,26 +278,23 @@ public function submitForm(array &$form, array &$form_state) { $operation = $form_state['values']['operation']; $cids = $form_state['values']['comments']; - if ($operation == 'delete') { - $comments = $this->commentStorage->loadMultiple($cids); - $this->commentStorage->delete($comments); - } - else { - foreach ($cids as $cid) { + foreach ($cids as $cid) { + // Delete operation handled in \Drupal\comment\Form\ConfirmDeleteMultiple. + if ($operation == 'unpublish') { $comment = $this->commentStorage->load($cid); - - if ($operation == 'unpublish') { - $comment->status->value = COMMENT_NOT_PUBLISHED; - $comment->save(); - } - elseif ($operation == 'publish') { - $comment->status->value = COMMENT_PUBLISHED; - $comment->save(); - } + $comment->status->value = COMMENT_NOT_PUBLISHED; + $comment->save(); + } + elseif ($operation == 'publish') { + $comment = $this->commentStorage->load($cid); + $comment->status->value = COMMENT_PUBLISHED; + $comment->save(); } } drupal_set_message($this->t('The update has been performed.')); - $form_state['redirect'] = 'admin/content/comment'; + $form_state['redirect_route'] = array( + 'route_name' => 'comment.admin', + ); Cache::invalidateTags(array('content' => TRUE)); }