DisqusEnabledNodeTypes.php in Disqus 8
File
src/Plugin/migrate/source/DisqusEnabledNodeTypes.php
View source
<?php
namespace Drupal\disqus\Plugin\migrate\source;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
class DisqusEnabledNodeTypes extends DrupalSqlBase {
protected function initializeIterator() {
return new \ArrayIterator($this
->values());
}
protected function values() {
$values = [];
if ($result = $this
->prepareQuery()
->execute()
->fetchAllKeyed()) {
$enabled_types = unserialize($result['disqus_nodetypes']);
$enabled_types = array_filter($enabled_types);
$defaults = unserialize($result['disqus_nodetypes_default']);
$defaults = array_filter($defaults);
foreach ($enabled_types as $type) {
$values[] = [
'type' => $type,
'default' => !empty($defaults[$type]),
];
}
}
return $values;
}
public function count($refresh = FALSE) {
return count($this
->values());
}
public function fields() {
return [
'type' => $this
->t('Content type with enabled Disqus'),
'default' => $this
->t('Default Disqus status for node type'),
];
}
public function query() {
return $this
->getDatabase()
->select('variable', 'v')
->fields('v', [
'name',
'value',
])
->condition('v.name', [
'disqus_nodetypes',
'disqus_nodetypes_default',
], 'IN');
}
public function getIds() {
$ids['type']['type'] = 'string';
return $ids;
}
}