|  | @@ -2,6 +2,8 @@
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  namespace Drupal\reinstall\Plugin\migrate\source;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +use Drupal\Core\Entity\EntityFieldManagerInterface;
 | 
	
		
			
				|  |  | +use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
 | 
	
		
			
				|  |  |  use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
 | 
	
		
			
				|  |  |  use Drupal\migrate\MigrateException;
 | 
	
		
			
				|  |  |  use Drupal\migrate\Plugin\migrate\source\SourcePluginBase;
 | 
	
	
		
			
				|  | @@ -22,6 +24,30 @@ abstract class SimpleSource extends SourcePluginBase implements ContainerFactory
 | 
	
		
			
				|  |  |     * @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}
 | 
	
	
		
			
				|  | @@ -35,7 +61,9 @@ abstract class SimpleSource extends SourcePluginBase implements ContainerFactory
 | 
	
		
			
				|  |  |    ) {
 | 
	
		
			
				|  |  |      $importPath = $container->getParameter('reinstall.path');
 | 
	
		
			
				|  |  |      $configuration['importPath'] = $importPath;
 | 
	
		
			
				|  |  | -    return new static($configuration, $pluginId, $pluginDefinition, $migration);
 | 
	
		
			
				|  |  | +    $ebi = $container->get('entity_type.bundle.info');
 | 
	
		
			
				|  |  | +    $efm = $container->get('entity_field.manager');
 | 
	
		
			
				|  |  | +    return new static($configuration, $pluginId, $pluginDefinition, $migration, $ebi, $efm);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    /**
 | 
	
	
		
			
				|  | @@ -45,6 +73,63 @@ 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.
 | 
	
		
			
				|  |  | +   *
 | 
	
		
			
				|  |  | +   * @param array $record
 | 
	
		
			
				|  |  | +   *   The raw source values.
 | 
	
		
			
				|  |  | +   *
 | 
	
		
			
				|  |  | +   * @return array
 | 
	
		
			
				|  |  | +   *   The flattened values.
 | 
	
		
			
				|  |  | +   *
 | 
	
		
			
				|  |  | +   * @see \Drupal\reinstall\Plugin\migrate\process\TermParent
 | 
	
		
			
				|  |  | +   */
 | 
	
		
			
				|  |  | +  protected function flattenRecord(array $record) {
 | 
	
		
			
				|  |  | +    $row = new Row($record);
 | 
	
		
			
				|  |  | +    $this->flattenRow($row);
 | 
	
		
			
				|  |  | +    return $row->getSource();
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    /**
 | 
	
		
			
				|  |  |     * Flatten a typical Drupal 8 field array to a 1-level array.
 | 
	
		
			
				|  |  |     */
 |