Skip to content
Snippets Groups Projects
Commit a983c280 authored by catch's avatar catch
Browse files

Issue #3069260 by quietone, andypost, guilhermevp, anmolgoyal74,...

Issue #3069260 by quietone, andypost, guilhermevp, anmolgoyal74, rahulkhandelwal1990, Meenakshi_j, hmendes, mikelutz, swatichouhan012: Deprecate Drupal\comment\Plugin\migrate\source\d6\Comment::prepareComment()
parent e33e4c71
No related branches found
No related tags found
No related merge requests found
......@@ -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');
......
name: Drupal 6 comment test
type: module
description: Provides a source plugin to test prepareComment deprecation.
package: Testing
version: VERSION
dependencies:
- drupal:comment
<?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);
}
}
......@@ -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}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment