VariableTranslation.php in Drupal 8
File
core/modules/migrate_drupal/src/Plugin/migrate/source/d6/VariableTranslation.php
View source
<?php
namespace Drupal\migrate_drupal\Plugin\migrate\source\d6;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
class VariableTranslation 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 = [];
$result = $this
->prepareQuery()
->execute()
->FetchAllAssoc('language');
foreach ($result as $i18n_variable) {
$values[]['language'] = $i18n_variable->language;
}
$result = $this
->prepareQuery()
->execute()
->FetchAll();
foreach ($result as $i18n_variable) {
foreach ($values as $key => $value) {
if ($values[$key]['language'] === $i18n_variable->language) {
$values[$key][$i18n_variable->name] = unserialize($i18n_variable->value);
break;
}
}
}
return $values;
}
public function count($refresh = FALSE) {
return $this
->initializeIterator()
->count();
}
public function fields() {
return array_combine($this->variables, $this->variables);
}
public function query() {
return $this
->getDatabase()
->select('i18n_variable', 'v')
->fields('v')
->condition('name', (array) $this->configuration['variables'], 'IN');
}
public function getIds() {
$ids['language']['type'] = 'string';
return $ids;
}
public function checkRequirements() {
if (!$this
->getDatabase()
->schema()
->tableExists('i18n_variable')) {
throw new RequirementsException("Source database table 'i18n_variable' does not exist");
}
parent::checkRequirements();
}
}