123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace Drupal\reinstall\Plugin\migrate\source;
- use Drupal\migrate\Plugin\MigrationInterface;
- use Drupal\migrate\Row;
- /**
- * Source plugin for terms from a YAML file.
- *
- * @MigrateSource(
- * id = "reinstall_terms"
- * )
- */
- class ReinstallTermSource extends SimpleSource {
- /**
- * Constructor.
- */
- public function __construct(
- array $configuration,
- string $pluginId,
- array $pluginDefinition,
- MigrationInterface $migration
- ) {
- parent::__construct($configuration, $pluginId, $pluginDefinition, $migration);
- $rawRecords = array_map([$this, 'flattenRecord'], $this->initialParse($configuration));
- $this->records = $rawRecords;
- }
- protected function flattenRecord($record) {
- $row = new Row($record);
- $this->flattenRow($row);
- return $row->getSource();
- }
- /**
- * {@inheritdoc}
- */
- public function fields() {
- $ret = [
- 'changed' => 'Modification timestamp',
- 'default_langcode' => 'ISO 639 default language code',
- 'description' => 'The entity description',
- 'langcode' => 'ISO 639 language code',
- 'name' => 'The term name (PK)',
- 'parent' => 'Parent term ID',
- 'path' => 'Optional path alias',
- 'tid' => 'Taxonomy term ID',
- 'uuid' => 'UUID',
- 'vid' => 'Vocabulary ID',
- 'weight' => 'Poids',
- ];
- return $ret;
- }
- /**
- * {@inheritdoc}
- */
- public function getIds() {
- $ids = [
- 'tid' => [
- 'type' => 'integer',
- ],
- ];
- return $ids;
- }
- /**
- * Obtain the term parents from either of their two formats.
- *
- * @param mixed $source
- * A parent, from the migration pipeline.
- *
- * @return mixed
- * The parent, as its target_id.
- *
- * @see (reinstall)/README.md
- */
- public static function getParent($source) {
- if (is_scalar($source)) {
- return $source;
- }
- elseif (isset($source['target_id'])) {
- return $source['target_id'];
- }
- }
- }
|