Mercurial > hg > isophonics-drupal-site
diff modules/contrib/migrate_plus/src/Plugin/Discovery/ConfigEntityDiscovery.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/contrib/migrate_plus/src/Plugin/Discovery/ConfigEntityDiscovery.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,49 @@ +<?php + +namespace Drupal\migrate_plus\Plugin\Discovery; + +use Drupal\Component\Plugin\Discovery\DiscoveryInterface; +use Drupal\Component\Plugin\Discovery\DiscoveryTrait; + +/** + * Allows configuration entities to define plugin definitions. + */ +class ConfigEntityDiscovery implements DiscoveryInterface { + + use DiscoveryTrait; + + /** + * Entity type to query. + * + * @var string + */ + protected $entityType; + + /** + * Construct a YamlDiscovery object. + * + * @param string $entity_type + * The entity type to query for. + */ + function __construct($entity_type) { + $this->entityType = $entity_type; + } + + /** + * {@inheritdoc} + */ + public function getDefinitions() { + $definition = \Drupal::entityTypeManager()->getDefinition($this->entityType); + $prefix = $definition->getConfigPrefix() . '.'; + $storage = \Drupal::service('config.storage'); + $query = \Drupal::entityQuery($this->entityType); + $ids = $query->execute(); + $definitions = []; + foreach ($ids as $id) { + $definitions[$id] = $storage->read($prefix . $id); + } + + return $definitions; + } + +}