diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 8ec7eaf246..47241c281d 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -5,8 +5,6 @@ * Install, update and uninstall functions for the Comment module. */ -use Drupal\Core\Config\FileStorage; -use Drupal\Core\Config\InstallStorage; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\StringTranslation\PluralTranslatableMarkup; use Drupal\Core\StringTranslation\TranslatableMarkup; @@ -186,33 +184,3 @@ function comment_update_8301() { $entity_type->set('entity_keys', $keys); $definition_update_manager->updateEntityType($entity_type); } - -/** - * Enable the comment admin view. - */ -function comment_update_8401() { - $module_handler = \Drupal::moduleHandler(); - // Skip the update if views is not installed. - if (!$module_handler->moduleExists('views')) { - return; - } - - $entity_type_manager = \Drupal::entityTypeManager(); - - // Save the comment delete action to config. - $config_install_path = $module_handler->getModule('comment')->getPath() . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY; - $storage = new FileStorage($config_install_path); - $entity_type_manager - ->getStorage('action') - ->create($storage->read('system.action.comment_delete_action')) - ->save(); - - // Save the comment admin view to config. - $optional_install_path = $module_handler->getModule('comment')->getPath() . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY; - $storage = new FileStorage($optional_install_path); - $entity_type_manager - ->getStorage('view') - ->create($storage->read('views.view.comment')) - ->save(); -} - diff --git a/core/modules/comment/comment.post_update.php b/core/modules/comment/comment.post_update.php new file mode 100644 index 0000000000..04bf2db28d --- /dev/null +++ b/core/modules/comment/comment.post_update.php @@ -0,0 +1,38 @@ +getModule('comment')->getPath() . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY; + $storage = new FileStorage($config_install_path); + $entity_type_manager + ->getStorage('action') + ->create($storage->read('system.action.comment_delete_action')) + ->save(); + + // Only create if the views module is enabled. + if (!$module_handler->moduleExists('views')) { + return; + } + + // Save the comment admin view to config. + $optional_install_path = $module_handler->getModule('comment')->getPath() . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY; + $storage = new FileStorage($optional_install_path); + $entity_type_manager + ->getStorage('view') + ->create($storage->read('views.view.comment')) + ->save(); +} diff --git a/core/modules/comment/config/optional/views.view.comment.yml b/core/modules/comment/config/optional/views.view.comment.yml index 0c46de95d1..52e6613a0d 100644 --- a/core/modules/comment/config/optional/views.view.comment.yml +++ b/core/modules/comment/config/optional/views.view.comment.yml @@ -506,7 +506,7 @@ display: group_type: group admin_label: '' operator: '=' - value: true + value: '1' group: 1 exposed: false expose: @@ -639,7 +639,7 @@ display: group_type: group admin_label: '' operator: '=' - value: false + value: '0' group: 1 exposed: false expose: diff --git a/core/modules/comment/src/Form/ConfirmDeleteMultiple.php b/core/modules/comment/src/Form/ConfirmDeleteMultiple.php index c5aaa838e3..3752ddd661 100644 --- a/core/modules/comment/src/Form/ConfirmDeleteMultiple.php +++ b/core/modules/comment/src/Form/ConfirmDeleteMultiple.php @@ -4,7 +4,6 @@ use Drupal\comment\CommentStorageInterface; use Drupal\user\PrivateTempStoreFactory; -use Drupal\Component\Utility\Html; use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; diff --git a/core/modules/comment/src/Plugin/Action/DeleteComment.php b/core/modules/comment/src/Plugin/Action/DeleteComment.php index db30f01b93..7f5651655a 100644 --- a/core/modules/comment/src/Plugin/Action/DeleteComment.php +++ b/core/modules/comment/src/Plugin/Action/DeleteComment.php @@ -1,10 +1,5 @@ executeMultiple(array($entity)); + $this->executeMultiple([$entity]); } /** diff --git a/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php index 931e271d6a..d579243e17 100644 --- a/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php +++ b/core/modules/comment/src/Plugin/Field/FieldFormatter/CommentPermalinkFormatter.php @@ -1,10 +1,5 @@ comment_body->value; } $comment_permalink = $comment->permalink(); - $attributes = $comment_permalink->getOption('attributes') ?: array(); - $attributes += array('title' => Unicode::truncate($body, 128)); + $attributes = $comment_permalink->getOption('attributes') ?: []; + $attributes += ['title' => Unicode::truncate($body, 128)]; $comment_permalink->setOption('attributes', $attributes); return $comment_permalink; } @@ -52,7 +47,7 @@ protected function getEntityUrl(EntityInterface $comment) { * {@inheritdoc} */ public static function isApplicable(FieldDefinitionInterface $field_definition) { - return parent::isApplicable($field_definition) && $field_definition->getName() === 'subject'; + return parent::isApplicable($field_definition) && $field_definition->getTargetEntityTypeId() === 'comment' && $field_definition->getName() === 'subject'; } } diff --git a/core/modules/comment/src/Plugin/views/field/CommentBulkForm.php b/core/modules/comment/src/Plugin/views/field/CommentBulkForm.php index 64face33c5..d4283734f7 100644 --- a/core/modules/comment/src/Plugin/views/field/CommentBulkForm.php +++ b/core/modules/comment/src/Plugin/views/field/CommentBulkForm.php @@ -1,13 +1,7 @@ loadedCommentedEntities)) { $result = $this->view->result; - $entity_ids_per_type = array(); + $entity_ids_per_type = []; foreach ($result as $value) { /** @var \Drupal\comment\CommentInterface $comment */ if ($comment = $this->getEntity($value)) { diff --git a/core/modules/comment/src/Tests/Update/CommentAdminViewUpdateTest.php b/core/modules/comment/src/Tests/Update/CommentAdminViewUpdateTest.php index 8741252915..930c152add 100644 --- a/core/modules/comment/src/Tests/Update/CommentAdminViewUpdateTest.php +++ b/core/modules/comment/src/Tests/Update/CommentAdminViewUpdateTest.php @@ -1,18 +1,14 @@ runUpdates(); // Ensure we can load the view from the storage after the update and it's // enabled. @@ -46,6 +42,11 @@ public function testUpdateHookN() { $this->assertTrue($comment_admin_view->enable(), 'Comment admin view is enabled.'); $comment_delete_action = $entity_type_manager->getStorage('action')->load('comment_delete_action'); $this->assertNotNull($comment_delete_action, 'Comment delete action imported'); + // Verify comment admin page is working after updates. + $account = $this->drupalCreateUser(['administer comments']); + $this->drupalLogin($account); + $this->drupalGet('admin/content/comment'); + $this->assertText(t('No comments available.')); } } diff --git a/core/modules/comment/src/Tests/Views/CommentAdminTest.php b/core/modules/comment/src/Tests/Views/CommentAdminTest.php index 2509cb988f..9097a26e32 100644 --- a/core/modules/comment/src/Tests/Views/CommentAdminTest.php +++ b/core/modules/comment/src/Tests/Views/CommentAdminTest.php @@ -1,10 +1,5 @@ id(); - $this->drupalPostForm('admin/content/comment/approval', $edit, t('Apply')); + $this->drupalPostForm('admin/content/comment/approval', $edit, t('Apply to selected items')); $this->assertText('Publish comment was applied to 1 item.', new FormattableMarkup('Operation "@operation" was performed on comment.', ['@operation' => 'publish'])); $this->drupalLogout(); @@ -104,11 +99,11 @@ public function testApprovalAdminInterface() { "comment_bulk_form[1]" => $comments[0]->id(), "comment_bulk_form[0]" => $comments[1]->id(), ]; - $this->drupalPostForm(NULL, $edit, t('Apply')); + $this->drupalPostForm(NULL, $edit, t('Apply to selected items')); $this->assertText(t('Unapproved comments (@count)', ['@count' => 0]), 'All comments were approved.'); // Test message when no comments selected. - $this->drupalPostForm('admin/content/comment', [], t('Apply')); + $this->drupalPostForm('admin/content/comment', [], t('Apply to selected items')); $this->assertText(t('Select one or more comments to perform the update on.')); // Delete multiple comments in one operation. $edit = [ @@ -117,7 +112,7 @@ public function testApprovalAdminInterface() { "comment_bulk_form[0]" => $comments[1]->id(), "comment_bulk_form[2]" => $anonymous_comment4->id(), ]; - $this->drupalPostForm(NULL, $edit, t('Apply')); + $this->drupalPostForm(NULL, $edit, t('Apply to selected items')); $this->assertText(t('Are you sure you want to delete these comments and all their children?'), 'Confirmation required.'); $this->drupalPostForm(NULL, [], t('Delete')); $this->assertText(t('No comments available.'), 'All comments were deleted.'); diff --git a/core/modules/comment/src/Tests/Views/CommentEditTest.php b/core/modules/comment/src/Tests/Views/CommentEditTest.php index d9733ed9c5..2a11ef9628 100644 --- a/core/modules/comment/src/Tests/Views/CommentEditTest.php +++ b/core/modules/comment/src/Tests/Views/CommentEditTest.php @@ -1,10 +1,5 @@ getMock('\Drupal\system\ActionConfigEntityInterface'); @@ -65,7 +60,7 @@ public function testConstructor() { $views_data->expects($this->any()) ->method('get') ->with('comment') - ->will($this->returnValue(array('table' => array('entity type' => 'comment')))); + ->will($this->returnValue(['table' => ['entity type' => 'comment']])); $container = new ContainerBuilder(); $container->set('views.views_data', $views_data); $container->set('string_translation', $this->getStringTranslationStub()); @@ -87,9 +82,9 @@ public function testConstructor() { ->getMock(); $definition['title'] = ''; - $options = array(); + $options = []; - $comment_bulk_form = new CommentBulkForm(array(), 'comment_bulk_form', $definition, $entity_manager, $language_manager); + $comment_bulk_form = new CommentBulkForm([], 'comment_bulk_form', $definition, $entity_manager, $language_manager); $comment_bulk_form->init($executable, $display, $options); $this->assertAttributeEquals(array_slice($actions, 0, -1, TRUE), 'actions', $comment_bulk_form); diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php index 5299f38e24..1c4b883a35 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php @@ -57,7 +57,7 @@ protected function getEntityCounts() { 'search_page' => 2, 'shortcut' => 2, 'shortcut_set' => 1, - 'action' => 22, + 'action' => 23, 'menu' => 8, 'taxonomy_term' => 7, 'taxonomy_vocabulary' => 6, @@ -65,7 +65,7 @@ protected function getEntityCounts() { 'user' => 7, 'user_role' => 6, 'menu_link_content' => 4, - 'view' => 15, + 'view' => 16, 'date_format' => 11, 'entity_form_display' => 19, 'entity_form_mode' => 1, diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php index e1e70bd5d8..248213ad45 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php @@ -63,7 +63,7 @@ protected function getEntityCounts() { 'search_page' => 2, 'shortcut' => 6, 'shortcut_set' => 2, - 'action' => 16, + 'action' => 17, 'menu' => 6, 'taxonomy_term' => 18, 'taxonomy_vocabulary' => 4, @@ -71,7 +71,7 @@ protected function getEntityCounts() { 'user' => 4, 'user_role' => 3, 'menu_link_content' => 7, - 'view' => 15, + 'view' => 16, 'date_format' => 11, 'entity_form_display' => 18, 'entity_form_mode' => 1,