12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?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;
- }
- public static function getParent($source) {
- if (is_scalar($source)) {
- return $source;
- }
- elseif (isset($source['target_id'])) {
- return $source['target_id'];
- }
- }
- }
|