AclTable.php in ACL 8
File
src/Plugin/migrate/destination/AclTable.php
View source
<?php
namespace Drupal\acl\Plugin\migrate\destination;
use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
use Drupal\migrate\Plugin\MigrateDestinationInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
class AclTable extends DestinationBase implements MigrateDestinationInterface {
protected $table_name;
protected $fields_list;
protected $ids = [
'acl_id' => [
'type' => 'integer',
],
];
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
$this->table_name = $this->configuration['table_name'];
$this->fields_list = $this->configuration['fields_list'];
if (!empty($this->configuration['ids'])) {
$this->ids = $this->configuration['ids'];
}
}
public function import(Row $row, array $old_destination_id_values = array()) {
$destination = $row
->getDestination();
$keys = array();
foreach (array_keys($this->ids) as $id) {
$keys[$id] = $destination[$id];
unset($destination[$id]);
}
\Drupal::database()
->merge($this->table_name)
->keys($keys)
->fields($destination)
->execute();
$return = array_map(function ($key) use ($row) {
return $row
->getDestinationProperty($key);
}, $keys);
return $return;
}
public function getIds() {
return $this->ids;
}
public function fields(MigrationInterface $migration = NULL) {
return array_combine($this->fields_list, $this->fields_list);
}
}