CommentType.php in Drupal 10
File
core/modules/comment/src/Plugin/migrate/source/CommentType.php
View source
<?php
namespace Drupal\comment\Plugin\migrate\source;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
class CommentType extends DrupalSqlBase {
public function query() {
return $this
->select('node_type', 't')
->fields('t', [
'type',
'name',
]);
}
public function prepareRow(Row $row) {
$node_type = $row
->getSourceProperty('type');
foreach (array_keys($this
->getCommentFields()) as $field) {
$row
->setSourceProperty($field, $this
->variableGet($field . '_' . $node_type, NULL));
}
return parent::prepareRow($row);
}
public function fields() {
return [
'name' => $this
->t('Human name of the parent node type.'),
'type' => $this
->t('Machine name of the parent node type.'),
] + $this
->getCommentFields();
}
protected function getCommentFields() {
return [
'comment' => $this
->t('Default comment setting'),
'comment_default_mode' => $this
->t('Default display mode'),
'comment_default_per_page' => $this
->t('Default comments per page'),
'comment_anonymous' => $this
->t('Anonymous commenting'),
'comment_subject_field' => $this
->t('Comment subject field'),
'comment_preview' => $this
->t('Preview comment'),
'comment_form_location' => $this
->t('Location of comment submission form'),
];
}
public function getIds() {
$ids['type']['type'] = 'string';
return $ids;
}
public function checkRequirements() {
parent::checkRequirements();
if (!$this
->moduleExists('node')) {
throw new RequirementsException('The node module is not enabled in the source site.', [
'source_module_additional' => 'node',
]);
}
}
}
Classes
Name |
Description |
CommentType |
Drupal 6/7 comment types source from database. |