|
@@ -11,32 +11,25 @@ namespace Drupal\reinstall\Plugin\migrate\source;
|
|
|
|
|
|
trait SimpleSourceTrait {
|
|
|
|
|
|
+ /**
|
|
|
+ * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
|
|
|
+ */
|
|
|
protected $sstEntityTypeBundleInfo;
|
|
|
|
|
|
+ /**
|
|
|
+ * @var \Drupal\Core\Entity\EntityFieldManagerInterface
|
|
|
+ */
|
|
|
protected $sstEntityFieldManager;
|
|
|
|
|
|
+ /**
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
protected $sstEntityType;
|
|
|
|
|
|
- protected function getEntityTypeBundleInfo() {
|
|
|
- if (!isset($this->sstEntityTypeBundleInfo)) {
|
|
|
- $this->sstEntityTypeBundleInfo = \Drupal::service('entity_type.bundle.info');
|
|
|
- }
|
|
|
-
|
|
|
- return $this->sstEntityTypeBundleInfo;
|
|
|
- }
|
|
|
-
|
|
|
- protected function getEntityFieldManager() {
|
|
|
- if (!isset($this->sstEntityFieldManager)) {
|
|
|
- $this->sstEntityFieldManager = \Drupal::service('entity_field.manager');
|
|
|
- }
|
|
|
-
|
|
|
- return $this->sstEntityFieldManager;
|
|
|
- }
|
|
|
-
|
|
|
- protected function getEntityType() {
|
|
|
- assert(isset($this->sstEntityType));
|
|
|
- return $this->sstEntityType;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
|
|
+ */
|
|
|
+ protected $sstEntityTypeManager;
|
|
|
|
|
|
/**
|
|
|
* {@inheritdoc}
|
|
@@ -79,4 +72,55 @@ trait SimpleSourceTrait {
|
|
|
return $fields;
|
|
|
}
|
|
|
|
|
|
+ protected function getEntityTypeBundleInfo() {
|
|
|
+ if (!isset($this->sstEntityTypeBundleInfo)) {
|
|
|
+ $this->sstEntityTypeBundleInfo = \Drupal::service('entity_type.bundle.info');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->sstEntityTypeBundleInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getEntityFieldManager() {
|
|
|
+ if (!isset($this->sstEntityFieldManager)) {
|
|
|
+ $this->sstEntityFieldManager = \Drupal::service('entity_field.manager');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->sstEntityFieldManager;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getEntityType() {
|
|
|
+ assert(isset($this->sstEntityType));
|
|
|
+ return $this->sstEntityType;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getEntityTypeManager() {
|
|
|
+ if (!isset($this->sstEntityTypeManager)) {
|
|
|
+ $this->sstEntityTypeManager = \Drupal::service('entity_type.manager');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->sstEntityTypeManager;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * {@inheritdoc}
|
|
|
+ */
|
|
|
+ public function getIds() {
|
|
|
+ $typeName = $this->getEntityType();
|
|
|
+
|
|
|
+ $typeDefinition = $this->getEntityTypeManager()->getDefinition($typeName);
|
|
|
+ $idName = $typeDefinition->getKey('id');
|
|
|
+ assert(!empty($idName));
|
|
|
+
|
|
|
+ $definitions = $this->getEntityFieldManager()->getBaseFieldDefinitions($typeName);
|
|
|
+ assert(isset($definitions[$idName]));
|
|
|
+ $idDefinition = $definitions[$idName];
|
|
|
+ $idType = $idDefinition->getType();
|
|
|
+ $ids = [
|
|
|
+ $idName => [
|
|
|
+ 'type' => $idType,
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $ids;
|
|
|
+ }
|
|
|
+
|
|
|
}
|