3 namespace Drupal\migrate_drupal\Plugin\migrate\source\d6;
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\Core\State\StateInterface;
7 use Drupal\migrate\Plugin\MigrationInterface;
8 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
11 * Drupal i18n_variable source from database.
14 * id = "d6_variable_translation",
15 * source_module = "system",
18 class VariableTranslation extends DrupalSqlBase {
21 * The variable names to fetch.
30 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager) {
31 parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
32 $this->variables = $this->configuration['variables'];
38 protected function initializeIterator() {
39 return new \ArrayIterator($this->values());
43 * Return the values of the variables specified in the plugin configuration.
46 * An associative array where the keys are the variables specified in the
47 * plugin configuration and the values are the values found in the source.
48 * A key/value pair is added for the language code. Only those values are
49 * returned that are actually in the database.
51 protected function values() {
53 $result = $this->prepareQuery()->execute()->FetchAllAssoc('language');
54 foreach ($result as $i18n_variable) {
55 $values[]['language'] = $i18n_variable->language;
57 $result = $this->prepareQuery()->execute()->FetchAll();
58 foreach ($result as $i18n_variable) {
59 foreach ($values as $key => $value) {
60 if ($values[$key]['language'] === $i18n_variable->language) {
61 $values[$key][$i18n_variable->name] = unserialize($i18n_variable->value);
72 public function count($refresh = FALSE) {
73 return $this->initializeIterator()->count();
79 public function fields() {
80 return array_combine($this->variables, $this->variables);
86 public function query() {
87 return $this->getDatabase()
88 ->select('i18n_variable', 'v')
90 ->condition('name', (array) $this->configuration['variables'], 'IN');
96 public function getIds() {
97 $ids['language']['type'] = 'string';