CommentVariable.php in Zircon Profile 8
File
core/modules/comment/src/Plugin/migrate/source/d6/CommentVariable.php
View source
<?php
namespace Drupal\comment\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
use Drupal\migrate\Plugin\migrate\source\DummyQueryTrait;
class CommentVariable extends DrupalSqlBase {
use DummyQueryTrait;
protected function initializeIterator() {
return new \ArrayIterator($this
->getCommentVariables());
}
public function count() {
return count($this
->getCommentVariables());
}
protected function getCommentVariables() {
$comment_prefixes = array_keys($this
->commentPrefixes());
$variables = array();
$node_types = $this
->select('node_type', 'nt')
->fields('nt', [
'type',
])
->execute()
->fetchCol();
foreach ($node_types as $node_type) {
foreach ($comment_prefixes as $prefix) {
$variables[] = $prefix . '_' . $node_type;
}
}
$return = array();
$values = $this
->select('variable', 'v')
->fields('v', [
'name',
'value',
])
->condition('name', $variables, 'IN')
->execute()
->fetchAllKeyed();
foreach ($node_types as $node_type) {
foreach ($comment_prefixes as $prefix) {
$name = $prefix . '_' . $node_type;
if (isset($values[$name])) {
$return[$node_type][$prefix] = unserialize($values[$name]);
}
}
}
foreach ($return as $node_type => $data) {
$return[$node_type]['node_type'] = $node_type;
$return[$node_type]['comment_type'] = empty($data['comment_subject_field']) ? 'comment_no_subject' : 'comment';
}
return $return;
}
public function fields() {
return $this
->commentPrefixes() + array(
'node_type' => $this
->t('The node type'),
'comment_type' => $this
->t('The comment type'),
);
}
protected function commentPrefixes() {
return array(
'comment' => $this
->t('Default comment setting'),
'comment_default_mode' => $this
->t('Default display mode'),
'comment_default_order' => $this
->t('Default display order'),
'comment_default_per_page' => $this
->t('Default comments per page'),
'comment_controls' => $this
->t('Comment controls'),
'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['node_type']['type'] = 'string';
return $ids;
}
}
Classes
Name |
Description |
CommentVariable |
Plugin annotation
@MigrateSource(
id = "d6_comment_variable"
) |