TempStore.php in Multiversion 8
File
src/Plugin/migrate/source/TempStore.php
View source
<?php
namespace Drupal\multiversion\Plugin\migrate\source;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface;
use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TempStore extends SourcePluginBase {
protected $tempStore;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static($configuration, $plugin_id, $plugin_definition, $migration, $container
->get('entity.manager'), $container
->get('keyvalue.expirable'));
}
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityManagerInterface $entity_manager, KeyValueExpirableFactoryInterface $temp_store_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $entity_manager);
$this->tempStore = $temp_store_factory
->get('multiversion_migration_' . $this->entityTypeId);
}
protected function initializeIterator() {
$values = $this->tempStore
->getAll();
$result = new \ArrayIterator($values);
@$result
->uksort([
$this,
'sortKeys',
]);
return $result;
}
public static function sortKeys(string $a, string $b) {
$default_language_id = \Drupal::languageManager()
->getDefaultLanguage()
->getId();
$a_contains_default_language_id = strpos($a, '.' . $default_language_id);
$b_contains_default_language_id = strpos($b, '.' . $default_language_id);
if ($a_contains_default_language_id !== FALSE && $b_contains_default_language_id === FALSE) {
return -1;
}
elseif ($a_contains_default_language_id === FALSE && $b_contains_default_language_id !== FALSE) {
return 1;
}
else {
return 0;
}
}
}