|
@@ -17,37 +17,14 @@ use Symfony\Component\Yaml\Yaml;
|
|
|
* Class SimpleSource provides the basic mechanisms to load a YML entity dump.
|
|
|
*/
|
|
|
abstract class SimpleSource extends SourcePluginBase implements ContainerFactoryPluginInterface {
|
|
|
+ use SimpleSourceTrait;
|
|
|
|
|
|
|
|
|
- * The source records.
|
|
|
+ * The source records. MUST be initialized in concrete classes __construct().
|
|
|
*
|
|
|
* @var array
|
|
|
*/
|
|
|
protected $records;
|
|
|
-
|
|
|
- * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
|
|
|
- */
|
|
|
- protected $entityTypeBundleInfo;
|
|
|
-
|
|
|
- * @var \Drupal\Core\Entity\EntityFieldManagerInterface
|
|
|
- */
|
|
|
- protected $entityFieldManager;
|
|
|
-
|
|
|
-
|
|
|
- * Constructor.
|
|
|
- */
|
|
|
- public function __construct(
|
|
|
- array $configuration,
|
|
|
- string $pluginId,
|
|
|
- array $pluginDefinition,
|
|
|
- MigrationInterface $migration,
|
|
|
- EntityTypeBundleInfoInterface $ebi,
|
|
|
- EntityFieldManagerInterface $efm
|
|
|
- ) {
|
|
|
- parent::__construct($configuration, $pluginId, $pluginDefinition, $migration);
|
|
|
- $this->entityTypeBundleInfo = $ebi;
|
|
|
- $this->entityFieldManager = $efm;
|
|
|
- }
|
|
|
|
|
|
|
|
|
* {@inheritdoc}
|
|
@@ -61,9 +38,7 @@ abstract class SimpleSource extends SourcePluginBase implements ContainerFactory
|
|
|
) {
|
|
|
$importPath = $container->getParameter('reinstall.path');
|
|
|
$configuration['importPath'] = $importPath;
|
|
|
- $ebi = $container->get('entity_type.bundle.info');
|
|
|
- $efm = $container->get('entity_field.manager');
|
|
|
- return new static($configuration, $pluginId, $pluginDefinition, $migration, $ebi, $efm);
|
|
|
+ return new static($configuration, $pluginId, $pluginDefinition, $migration);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -73,46 +48,6 @@ abstract class SimpleSource extends SourcePluginBase implements ContainerFactory
|
|
|
return count($this->records);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * {@inheritdoc}
|
|
|
- */
|
|
|
- public function fields() {
|
|
|
- $bundles = $this->entityTypeBundleInfo->getBundleInfo(static::ENTITY_TYPE);
|
|
|
- $rows = [];
|
|
|
-
|
|
|
- foreach ($bundles as $bundleName => $bundle) {
|
|
|
- $fieldDefinitions = $this->entityFieldManager->getFieldDefinitions(static::ENTITY_TYPE,
|
|
|
- $bundleName);
|
|
|
- foreach ($fieldDefinitions as $fieldName => $fieldDefinition) {
|
|
|
- $rows[$fieldName][$bundleName] = $fieldDefinition->getLabel();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $fields = [];
|
|
|
- $singleBundle = count($bundles) === 1;
|
|
|
- foreach ($rows as $fieldName => $labels) {
|
|
|
- if ($singleBundle) {
|
|
|
- $fields[$fieldName] = reset($labels);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (count(array_unique($labels)) === 1) {
|
|
|
- $fields[$fieldName] = reset($labels);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- $ret = [];
|
|
|
- ksort($labels);
|
|
|
- foreach ($labels as $ct => $label) {
|
|
|
- $ret[] = $this->t('@ct: @label', ['@ct' => $ct, '@label' => $label]);
|
|
|
- }
|
|
|
- $fields[$fieldName] = implode(', ', $ret);
|
|
|
- }
|
|
|
-
|
|
|
- ksort($fields);
|
|
|
- return $fields;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
* Flatten the field hierarchy. Not correct for all cases.
|
|
|
*
|