MultiStepStorage.php in User Merge 2.x
File
src/MultiStepStorage.php
View source
<?php
namespace Drupal\usermerge;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\user\UserInterface;
class MultiStepStorage implements MultiStepStorageInterface {
protected $store;
protected $userStorage;
public function __construct(PrivateTempStoreFactory $temp_store_factory, EntityTypeManagerInterface $entity_type_manager) {
$this->store = $temp_store_factory
->get('usermerge');
$this->userStorage = $entity_type_manager
->getStorage('user');
}
public function setValues($property, array $values) : void {
$skip_values = [
'form_build_id',
'form_token',
'form_id',
];
foreach ($skip_values as $skip_value) {
if (isset($values[$skip_value])) {
unset($values[$skip_value]);
}
}
foreach ($values as $key => $value) {
if (is_object($value)) {
unset($values[$key]);
}
}
$this->store
->set($property, $values);
}
public function getValueFromStore($property, $name) {
$values = $this->store
->get($property);
if (isset($values[$name])) {
return $values[$name];
}
return NULL;
}
public function getValuesFromStore($property) {
$values = $this->store
->get($property);
if (is_null($values)) {
$values = [];
}
return $values;
}
public function getRetiredAccount() {
$values = $this->store
->get('');
if (!isset($values['retire'])) {
return NULL;
}
$user = $this->userStorage
->load($values['retire']);
if ($user instanceof UserInterface) {
return $user;
}
return NULL;
}
public function getRetainedAccount() {
$values = $this->store
->get('');
if (!isset($values['retain'])) {
return NULL;
}
$user = $this->userStorage
->load($values['retain']);
if ($user instanceof UserInterface) {
return $user;
}
return NULL;
}
public function delete($property) : void {
$this->store
->delete($property);
}
}