Variable.php in Drupal 8
File
core/modules/migrate_drupal/src/Plugin/migrate/source/Variable.php
View source
<?php
namespace Drupal\migrate_drupal\Plugin\migrate\source;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Plugin\MigrationInterface;
class Variable extends DrupalSqlBase {
protected $variables;
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_type_manager);
$this->variables = $this->configuration['variables'];
}
protected function initializeIterator() {
return new \ArrayIterator([
$this
->values(),
]);
}
protected function values() {
$values['id'] = reset($this->variables);
return $values + array_map('unserialize', $this
->prepareQuery()
->execute()
->fetchAllKeyed());
}
public function count($refresh = FALSE) {
return 1;
}
public function fields() {
return array_combine($this->variables, $this->variables);
}
public function query() {
return $this
->getDatabase()
->select('variable', 'v')
->fields('v', [
'name',
'value',
])
->condition('name', $this->variables, 'IN');
}
public function getIds() {
$ids['id']['type'] = 'string';
return $ids;
}
}
Classes
Name |
Description |
Variable |
Drupal variable source from database. |