class EntityExists
Same name in other branches
- 8.9.x core/modules/migrate/src/Plugin/migrate/process/EntityExists.php \Drupal\migrate\Plugin\migrate\process\EntityExists
- 10 core/modules/migrate/src/Plugin/migrate/process/EntityExists.php \Drupal\migrate\Plugin\migrate\process\EntityExists
- 11.x core/modules/migrate/src/Plugin/migrate/process/EntityExists.php \Drupal\migrate\Plugin\migrate\process\EntityExists
This plugin checks if a given entity exists.
Example usage with configuration:
field_tags:
plugin: entity_exists
source: tid
entity_type: taxonomy_term
Plugin annotation
@MigrateProcessPlugin(
id = "entity_exists"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\migrate\ProcessPluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\migrate\Plugin\MigrateProcessInterface
- class \Drupal\migrate\Plugin\migrate\process\EntityExists extends \Drupal\migrate\ProcessPluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\migrate\ProcessPluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\migrate\Plugin\MigrateProcessInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of EntityExists
File
-
core/
modules/ migrate/ src/ Plugin/ migrate/ process/ EntityExists.php, line 29
Namespace
Drupal\migrate\Plugin\migrate\processView source
class EntityExists extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* The entity storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $storage;
/**
* EntityExists constructor.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param $storage
* The entity storage.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->storage = $storage;
}
/**
* {@inheritdoc}
*/
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')
->getStorage($configuration['entity_type']));
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (is_array($value)) {
$value = reset($value);
}
$entity = $this->storage
->load($value);
if ($entity instanceof EntityInterface) {
return $entity->id();
}
return FALSE;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
EntityExists::$storage | protected | property | The entity storage. | ||
EntityExists::create | public static | function | Creates an instance of the plugin. | Overrides ContainerFactoryPluginInterface::create | |
EntityExists::transform | public | function | Performs the associated process. | Overrides ProcessPluginBase::transform | |
EntityExists::__construct | public | function | EntityExists constructor. | ||
PluginInspectionInterface::getPluginDefinition | public | function | Gets the definition of the plugin implementation. | 6 | |
PluginInspectionInterface::getPluginId | public | function | Gets the plugin_id of the plugin instance. | 2 | |
ProcessPluginBase::multiple | public | function | Indicates whether the returned value requires multiple handling. | Overrides MigrateProcessInterface::multiple | 3 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.