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 = "variable_translation"
17 class VariableTranslation extends DrupalSqlBase {
20 * The variable names to fetch.
29 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager) {
30 parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
31 $this->variables = $this->configuration['variables'];
37 protected function initializeIterator() {
38 return new \ArrayIterator($this->values());
42 * Return the values of the variables specified in the plugin configuration.
45 * An associative array where the keys are the variables specified in the
46 * plugin configuration and the values are the values found in the source.
47 * A key/value pair is added for the language code. Only those values are
48 * returned that are actually in the database.
50 protected function values() {
52 $result = $this->prepareQuery()->execute()->FetchAllAssoc('language');
53 foreach ($result as $i18n_variable) {
54 $values[]['language'] = $i18n_variable->language;
56 $result = $this->prepareQuery()->execute()->FetchAll();
57 foreach ($result as $i18n_variable) {
58 foreach ($values as $key => $value) {
59 if ($values[$key]['language'] === $i18n_variable->language) {
60 $values[$key][$i18n_variable->name] = unserialize($i18n_variable->value);
71 public function count($refresh = FALSE) {
72 return $this->initializeIterator()->count();
78 public function fields() {
79 return array_combine($this->variables, $this->variables);
85 public function query() {
86 return $this->getDatabase()
87 ->select('i18n_variable', 'v')
89 ->condition('name', (array) $this->configuration['variables'], 'IN');
95 public function getIds() {
96 $ids['language']['type'] = 'string';