DisqusEntityType.php in Disqus 8
File
src/Plugin/migrate/process/DisqusEntityType.php
View source
<?php
namespace Drupal\disqus\Plugin\migrate\process;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Drupal\migrate\Entity\MigrationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateSkipRowException;
class DisqusEntityType extends ProcessPluginBase implements ContainerFactoryPluginInterface {
protected $entityTypeManager;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'));
}
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$id_parts = explode("/", $value);
$entity = $this->entityTypeManager
->getDefinition($id_parts[0], FALSE);
if ($entity == NULL) {
throw new MigrateSkipRowException();
}
return $id_parts[0];
}
}