diff --git a/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php b/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php index fb702a9dd3cef6529ca96cfc125f9c50e854e0ee..ffd4e13f0a237e3c62118dd242ad9c16cc35c5e2 100644 --- a/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php +++ b/core/modules/comment/src/Plugin/migrate/source/d6/Comment.php @@ -39,10 +39,16 @@ public function query() { * {@inheritdoc} */ public function prepareRow(Row $row) { - // @todo Remove the call to ->prepareComment() in - // https://www.drupal.org/project/drupal/issues/3069260 when the Drupal 9 - // branch opens. - return parent::prepareRow($this->prepareComment($row)); + // In D6, status=0 means published, while in D8 means the opposite. + $row->setSourceProperty('status', !$row->getSourceProperty('status')); + + // If node did not have a language, use site default language as a fallback. + if (!$row->getSourceProperty('language')) { + $language_default = $this->variableGet('language_default', NULL); + $language = $language_default ? $language_default->language : 'en'; + $row->setSourceProperty('language', $language); + } + return parent::prepareRow($row); } /** @@ -58,11 +64,13 @@ public function prepareRow(Row $row) { * Passing a Row with a frozen source to this method will trigger an * \Exception when attempting to set the source properties. * - * @todo Remove usages of this method and deprecate for removal in - * https://www.drupal.org/project/drupal/issues/3069260 when the Drupal 9 - * branch opens. + * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. No direct + * replacement is provided. + * + * @see https://www.drupal.org/node/3221964 */ protected function prepareComment(Row $row) { + @trigger_error(__METHOD__ . '() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3221964', E_USER_DEPRECATED); if ($this->variableGet('comment_subject_field_' . $row->getSourceProperty('type'), 1)) { // Comment subject visible. $row->setSourceProperty('field_name', 'comment'); diff --git a/core/modules/comment/tests/modules/d6_comment_test/d6_comment_test.info.yml b/core/modules/comment/tests/modules/d6_comment_test/d6_comment_test.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..9bbeadd7ce1378e9ddde6fbcf2060aaab6eb8844 --- /dev/null +++ b/core/modules/comment/tests/modules/d6_comment_test/d6_comment_test.info.yml @@ -0,0 +1,7 @@ +name: Drupal 6 comment test +type: module +description: Provides a source plugin to test prepareComment deprecation. +package: Testing +version: VERSION +dependencies: + - drupal:comment diff --git a/core/modules/comment/tests/modules/d6_comment_test/src/Plugin/migrate/source/d6/Comment.php b/core/modules/comment/tests/modules/d6_comment_test/src/Plugin/migrate/source/d6/Comment.php new file mode 100644 index 0000000000000000000000000000000000000000..9bd4a4ddce0f9fbe7e0e3378bf1e4b96a68304c4 --- /dev/null +++ b/core/modules/comment/tests/modules/d6_comment_test/src/Plugin/migrate/source/d6/Comment.php @@ -0,0 +1,25 @@ +<?php + +namespace Drupal\d6_comment_test\Plugin\migrate\source\d6; + +use Drupal\comment\Plugin\migrate\source\d6\Comment as CoreComment; +use Drupal\migrate\Row; + +/** + * Test source plugin for deprecation testing. + * + * @MigrateSource( + * id = "d6_comment_test", + * source_module = "comment" + * ) + */ +class Comment extends CoreComment { + + /** + * Allow access to protected method. + */ + public function prepareComment(Row $row) { + return parent::prepareComment($row); + } + +} diff --git a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentTest.php b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentTest.php index 90c31cfdb3d0dcecd01cffce536e1041b092989d..658080b03524ba7fd7fe3397a7930f82af0fa4e3 100644 --- a/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentTest.php +++ b/core/modules/comment/tests/src/Kernel/Plugin/migrate/source/d6/CommentTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\comment\Kernel\Plugin\migrate\source\d6; +use Drupal\migrate\Row; use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase; /** @@ -15,7 +16,18 @@ class CommentTest extends MigrateSqlSourceTestBase { /** * {@inheritdoc} */ - protected static $modules = ['comment', 'migrate_drupal']; + protected static $modules = ['comment', 'd6_comment_test', 'migrate_drupal']; + + /** + * @group legacy + */ + public function testPrepareCommentDeprecation() { + $this->expectDeprecation('Drupal\comment\Plugin\migrate\source\d6\Comment::prepareComment() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. No direct replacement is provided. See https://www.drupal.org/node/3221964'); + $migration = $this->createMock('Drupal\migrate\Plugin\MigrationInterface'); + $mgr = \Drupal::service('plugin.manager.migrate.source'); + $plugin = $mgr->createInstance('d6_comment_test', [], $migration); + $plugin->prepareComment(new Row()); + } /** * {@inheritdoc}