X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcomment%2Fsrc%2FForm%2FCommentAdminOverview.php;h=3b97d0d1c48b511ca2bf14df19c2da998f59649e;hb=1c1cb0980bfa6caf0c24cce671b6bb541dc87583;hp=24f8b0aa2e6dad12d525cfd0860262edb98cf26c;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/comment/src/Form/CommentAdminOverview.php b/web/core/modules/comment/src/Form/CommentAdminOverview.php index 24f8b0aa2..3b97d0d1c 100644 --- a/web/core/modules/comment/src/Form/CommentAdminOverview.php +++ b/web/core/modules/comment/src/Form/CommentAdminOverview.php @@ -3,26 +3,28 @@ namespace Drupal\comment\Form; use Drupal\comment\CommentInterface; -use Drupal\comment\CommentStorageInterface; use Drupal\Component\Utility\Unicode; use Drupal\Core\Datetime\DateFormatterInterface; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\TempStore\PrivateTempStoreFactory; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides the comments overview administration form. + * + * @internal */ class CommentAdminOverview extends FormBase { /** - * The entity storage. + * The entity type manager. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityManager; + protected $entityTypeManager; /** * The comment storage. @@ -45,23 +47,31 @@ class CommentAdminOverview extends FormBase { */ protected $moduleHandler; + /** + * The tempstore factory. + * + * @var \Drupal\Core\TempStore\PrivateTempStoreFactory + */ + protected $tempStoreFactory; + /** * Creates a CommentAdminOverview form. * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity manager service. - * @param \Drupal\comment\CommentStorageInterface $comment_storage - * The comment storage. * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter * The date formatter service. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. + * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory + * The tempstore factory. */ - public function __construct(EntityManagerInterface $entity_manager, CommentStorageInterface $comment_storage, DateFormatterInterface $date_formatter, ModuleHandlerInterface $module_handler) { - $this->entityManager = $entity_manager; - $this->commentStorage = $comment_storage; + public function __construct(EntityTypeManagerInterface $entity_type_manager, DateFormatterInterface $date_formatter, ModuleHandlerInterface $module_handler, PrivateTempStoreFactory $temp_store_factory) { + $this->entityTypeManager = $entity_type_manager; + $this->commentStorage = $entity_type_manager->getStorage('comment'); $this->dateFormatter = $date_formatter; $this->moduleHandler = $module_handler; + $this->tempStoreFactory = $temp_store_factory; } /** @@ -69,10 +79,10 @@ class CommentAdminOverview extends FormBase { */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager'), - $container->get('entity.manager')->getStorage('comment'), + $container->get('entity_type.manager'), $container->get('date.formatter'), - $container->get('module_handler') + $container->get('module_handler'), + $container->get('tempstore.private') ); } @@ -171,7 +181,9 @@ class CommentAdminOverview extends FormBase { } foreach ($commented_entity_ids as $entity_type => $ids) { - $commented_entities[$entity_type] = $this->entityManager->getStorage($entity_type)->loadMultiple($ids); + $commented_entities[$entity_type] = $this->entityTypeManager + ->getStorage($entity_type) + ->loadMultiple($ids); } foreach ($comments as $comment) { @@ -255,23 +267,33 @@ class CommentAdminOverview extends FormBase { public function submitForm(array &$form, FormStateInterface $form_state) { $operation = $form_state->getValue('operation'); $cids = $form_state->getValue('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->setPublished(FALSE); + /** @var \Drupal\comment\CommentInterface[] $comments */ + $comments = $this->commentStorage->loadMultiple($cids); + if ($operation != 'delete') { + foreach ($comments as $comment) { + if ($operation == 'unpublish') { + $comment->setUnpublished(); + } + elseif ($operation == 'publish') { + $comment->setPublished(); + } $comment->save(); } - elseif ($operation == 'publish') { - $comment = $this->commentStorage->load($cid); - $comment->setPublished(TRUE); - $comment->save(); + $this->messenger()->addStatus($this->t('The update has been performed.')); + $form_state->setRedirect('comment.admin'); + } + else { + $info = []; + /** @var \Drupal\comment\CommentInterface $comment */ + foreach ($comments as $comment) { + $langcode = $comment->language()->getId(); + $info[$comment->id()][$langcode] = $langcode; } + $this->tempStoreFactory + ->get('entity_delete_multiple_confirm') + ->set($this->currentUser()->id() . ':comment', $info); + $form_state->setRedirect('entity.comment.delete_multiple_form'); } - drupal_set_message($this->t('The update has been performed.')); - $form_state->setRedirect('comment.admin'); } }