comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\migrate_plus\Plugin\Discovery;
4
5 use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
6 use Drupal\Component\Plugin\Discovery\DiscoveryTrait;
7
8 /**
9 * Allows configuration entities to define plugin definitions.
10 */
11 class ConfigEntityDiscovery implements DiscoveryInterface {
12
13 use DiscoveryTrait;
14
15 /**
16 * Entity type to query.
17 *
18 * @var string
19 */
20 protected $entityType;
21
22 /**
23 * Construct a YamlDiscovery object.
24 *
25 * @param string $entity_type
26 * The entity type to query for.
27 */
28 function __construct($entity_type) {
29 $this->entityType = $entity_type;
30 }
31
32 /**
33 * {@inheritdoc}
34 */
35 public function getDefinitions() {
36 $definition = \Drupal::entityTypeManager()->getDefinition($this->entityType);
37 $prefix = $definition->getConfigPrefix() . '.';
38 $storage = \Drupal::service('config.storage');
39 $query = \Drupal::entityQuery($this->entityType);
40 $ids = $query->execute();
41 $definitions = [];
42 foreach ($ids as $id) {
43 $definitions[$id] = $storage->read($prefix . $id);
44 }
45
46 return $definitions;
47 }
48
49 }