diff --git a/modules/custom/materio_migrate/config/install/_migrate_plus.migration.d7_taxonomy_vocabulary_company.yml b/modules/custom/materio_migrate/config/install/_migrate_plus.migration.d7_taxonomy_vocabulary_company.yml deleted file mode 100644 index eb9d198..0000000 --- a/modules/custom/materio_migrate/config/install/_migrate_plus.migration.d7_taxonomy_vocabulary_company.yml +++ /dev/null @@ -1,35 +0,0 @@ -id: d7_taxonomy_vocabulary_company -label: Taxonomy vocabularies Company -migration_group: d7_materio -migration_tags: - - Drupal 7 - - Configuration - - Materio - -source: - plugin: d7_taxonomy_vocabulary - bundle: company - -destination: - plugin: entity:taxonomy_vocabulary - -process: - vid: - - - plugin: make_unique_entity_field - source: machine_name - entity_type: taxonomy_vocabulary - field: vid - length: 32 - migrated: true - - - # This plugin checks if the vocabulary being migrated is the one used by - # Forum. If so, we use the machine name that Forum expects. Otherwise, we - # leave it unchanged. - plugin: forum_vocabulary - machine_name: forums - label: name - name: name - description: description - hierarchy: hierarchy - weight: weight diff --git a/modules/custom/materio_migrate/config/install/_migrate_plus.migration.d7_taxonomy_vocabulary_showroom.yml b/modules/custom/materio_migrate/config/install/_migrate_plus.migration.d7_taxonomy_vocabulary_showroom.yml deleted file mode 100644 index 2d3945c..0000000 --- a/modules/custom/materio_migrate/config/install/_migrate_plus.migration.d7_taxonomy_vocabulary_showroom.yml +++ /dev/null @@ -1,35 +0,0 @@ -id: d7_taxonomy_vocabulary_showroom -label: Taxonomy vocabularies Showroom -migration_group: d7_materio -migration_tags: - - Drupal 7 - - Configuration - - Materio - -source: - plugin: d7_taxonomy_vocabulary - bundle: showroom - -destination: - plugin: entity:taxonomy_vocabulary - -process: - vid: - - - plugin: make_unique_entity_field - source: machine_name - entity_type: taxonomy_vocabulary - field: vid - length: 32 - migrated: true - - - # This plugin checks if the vocabulary being migrated is the one used by - # Forum. If so, we use the machine name that Forum expects. Otherwise, we - # leave it unchanged. - plugin: forum_vocabulary - machine_name: forums - label: name - name: name - description: description - hierarchy: hierarchy - weight: weight diff --git a/modules/custom/materio_migrate/config/install/_migrate_plus.migration.d7_taxonomy_vocabulary_tags.yml b/modules/custom/materio_migrate/config/install/_migrate_plus.migration.d7_taxonomy_vocabulary_tags.yml deleted file mode 100644 index a54e4f4..0000000 --- a/modules/custom/materio_migrate/config/install/_migrate_plus.migration.d7_taxonomy_vocabulary_tags.yml +++ /dev/null @@ -1,35 +0,0 @@ -id: d7_taxonomy_vocabulary_tags -label: Taxonomy vocabularies Tags -migration_group: d7_materio -migration_tags: - - Drupal 7 - - Configuration - - Materio - -source: - plugin: d7_taxonomy_vocabulary - bundle: tag_libres - -destination: - plugin: entity:taxonomy_vocabulary - -process: - vid: - - - plugin: make_unique_entity_field - source: machine_name - entity_type: taxonomy_vocabulary - field: vid - length: 32 - migrated: true - - - # This plugin checks if the vocabulary being migrated is the one used by - # Forum. If so, we use the machine name that Forum expects. Otherwise, we - # leave it unchanged. - plugin: forum_vocabulary - machine_name: forums - label: name - name: name - description: description - hierarchy: hierarchy - weight: weight diff --git a/modules/custom/materio_migrate/config/install/_migrate_plus.migration.d7_taxonomy_vocabulary_thesaurus.yml b/modules/custom/materio_migrate/config/install/_migrate_plus.migration.d7_taxonomy_vocabulary_thesaurus.yml deleted file mode 100644 index 55ba837..0000000 --- a/modules/custom/materio_migrate/config/install/_migrate_plus.migration.d7_taxonomy_vocabulary_thesaurus.yml +++ /dev/null @@ -1,35 +0,0 @@ -id: d7_taxonomy_vocabulary_thesaurus -label: Taxonomy vocabularies Thesaurus -migration_group: d7_materio -migration_tags: - - Drupal 7 - - Configuration - - Materio - -source: - plugin: d7_taxonomy_vocabulary - bundle: onthologie - -destination: - plugin: entity:taxonomy_vocabulary - -process: - vid: - - - plugin: make_unique_entity_field - source: machine_name - entity_type: taxonomy_vocabulary - field: vid - length: 32 - migrated: true - - - # This plugin checks if the vocabulary being migrated is the one used by - # Forum. If so, we use the machine name that Forum expects. Otherwise, we - # leave it unchanged. - plugin: forum_vocabulary - machine_name: forums - label: name - name: name - description: description - hierarchy: hierarchy - weight: weight diff --git a/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_node_entity_translation_materiau.yml b/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_node_entity_translation_materiau.yml index 37573cf..73de92d 100644 --- a/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_node_entity_translation_materiau.yml +++ b/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_node_entity_translation_materiau.yml @@ -38,3 +38,22 @@ process: revision_log: log revision_timestamp: timestamp content_translation_source: source + + # TODO: mémo (field_memo) + # TODO: nature (field_nature_titre) + # TODO: description (field_description) + # TODO: thesaurus (field_onthologie) + # TODO: tags (field_tags_libres) + # TODO: images (field_materiau_image) + # TODO: videos (field_video_filter) + # TODO: manufacturer (field_company_fab) + # TODO: distributor (field_company_distrib) + # TODO: fichiers (field_attachments) + # TODO: materiaux liés (field_materiau_ref) + # TODO: breves liées (field_breve_ref) + # TODO: samples (field_location) + # TODO: famille (field_famille) + # TODO: identifiant (field_identifiant) + # TODO: reference materio (field_reference_materio) COMPUTED + # TODO: workflow + # TODO: translations diff --git a/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_company.yml b/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_company.yml index 097a542..3c3349b 100644 --- a/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_company.yml +++ b/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_company.yml @@ -9,27 +9,19 @@ migration_tags: deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver source: - plugin: d7_taxonomy_term + plugin: d7_taxonomy_term_company bundle: company destination: plugin: entity:taxonomy_term - bundle: company - -# migration_dependencies: -# required: -# - d7_taxonomy_vocabulary_company -# optional: -# - d7_field_instance process: # If you are using this file to build a custom migration consider removing # the tid field to allow incremental migrations. - tid: tid + # tid: tid vid: - plugin: migration_lookup - migration: d7_taxonomy_vocabulary_company - source: vid + plugin: default_value + default_value: company name: name 'description/value': description 'description/format': format @@ -49,3 +41,5 @@ process: source: '@parent_id' forum_container: is_container changed: timestamp + + # TODO: tode node company diff --git a/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_showroom.yml b/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_showroom.yml index 0a7aa2c..fcc5e3c 100644 --- a/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_showroom.yml +++ b/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_showroom.yml @@ -9,27 +9,19 @@ migration_tags: deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver source: - plugin: d7_taxonomy_term + plugin: d7_taxonomy_term_showroom bundle: showroom destination: plugin: entity:taxonomy_term - bundle: showroom - -# migration_dependencies: -# required: -# - d7_taxonomy_vocabulary_showroom -# optional: -# - d7_field_instance process: # If you are using this file to build a custom migration consider removing # the tid field to allow incremental migrations. - tid: tid + # tid: tid vid: - plugin: migration_lookup - migration: d7_taxonomy_vocabulary_showroom - source: vid + plugin: default_value + default_value: showroom name: name 'description/value': description 'description/format': format @@ -49,3 +41,5 @@ process: source: '@parent_id' forum_container: is_container changed: timestamp + + # TODO: tode node showroom diff --git a/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_tags.yml b/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_tags.yml index d018e48..7351029 100644 --- a/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_tags.yml +++ b/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_tags.yml @@ -9,27 +9,19 @@ migration_tags: deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver source: - plugin: d7_taxonomy_term + plugin: d7_taxonomy_term_tags bundle: tag_libres destination: plugin: entity:taxonomy_term - bundle: tags - -# migration_dependencies: -# required: -# - d7_taxonomy_vocabulary_tags -# optional: -# - d7_field_instance process: # If you are using this file to build a custom migration consider removing # the tid field to allow incremental migrations. # tid: tid vid: - plugin: migration_lookup - migration: d7_taxonomy_vocabulary_tags - source: vid + plugin: default_value + default_value: tags name: name 'description/value': description 'description/format': format @@ -49,3 +41,8 @@ process: source: '@parent_id' forum_container: is_container changed: timestamp + + #synonyms + field_synonyms: synonyms + + # TODO translation diff --git a/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_thesaurus.yml b/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_thesaurus.yml index e6eea10..dad8413 100644 --- a/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_thesaurus.yml +++ b/modules/custom/materio_migrate/config/install/migrate_plus.migration.d7_taxonomy_term_thesaurus.yml @@ -9,27 +9,19 @@ migration_tags: deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver source: - plugin: d7_taxonomy_term + plugin: d7_taxonomy_term_thesaurus bundle: onthologie destination: plugin: entity:taxonomy_term - bundle: thesaurus - -# migration_dependencies: -# required: -# - d7_taxonomy_vocabulary_thesaurus -# optional: -# - d7_field_instance process: # If you are using this file to build a custom migration consider removing # the tid field to allow incremental migrations. - tid: tid + # tid: tid vid: - plugin: migration_lookup - migration: d7_taxonomy_vocabulary_thesaurus - source: vid + plugin: default_value + default_value: thesaurus name: name 'description/value': description 'description/format': format @@ -49,3 +41,11 @@ process: source: '@parent_id' forum_container: is_container changed: timestamp + + #synonyms + field_synonyms: synonyms + + # used on advanced search + field_used_on_advanced_search: advanced_search + + # TODO translation diff --git a/modules/custom/materio_migrate/materio_migrate.info.yml b/modules/custom/materio_migrate/materio_migrate.info.yml index c281896..26e8aa5 100644 --- a/modules/custom/materio_migrate/materio_migrate.info.yml +++ b/modules/custom/materio_migrate/materio_migrate.info.yml @@ -4,23 +4,19 @@ description: Defines custom migration for materio (from d7 to d8). core: 8.x package: Materio dependencies: + - config_devel - drupal:migrate - drupal:migrate_drupal - drupal:migrate_drupal_multilingual - # - drupal:field_group_migrate - migrate_plus:migrate_plus - migrate_tools:migrate_tools - - config_devel + # - drupal:field_group_migrate config_devel: install: - migrate_plus.migration_group.d7_materio - # - migrate_plus.migration.d7_taxonomy_vocabulary_tags - - migrate_plus.migration.d7_taxonomy_term_tags - # - migrate_plus.migration.d7_taxonomy_vocabulary_thesaurus - migrate_plus.migration.d7_taxonomy_term_thesaurus - # - migrate_plus.migration.d7_taxonomy_vocabulary_showroom + - migrate_plus.migration.d7_taxonomy_term_tags - migrate_plus.migration.d7_taxonomy_term_showroom - # - migrate_plus.migration.d7_taxonomy_vocabulary_company - migrate_plus.migration.d7_taxonomy_term_company - migrate_plus.migration.d7_node_entity_translation_materiau diff --git a/modules/custom/materio_migrate/readme.md b/modules/custom/materio_migrate/readme.md index 9a1f3fb..5d23028 100644 --- a/modules/custom/materio_migrate/readme.md +++ b/modules/custom/materio_migrate/readme.md @@ -1,3 +1,5 @@ +[debugging-migrations](https://www.drupal.org/docs/8/api/migrate-api/debugging-migrations) + https://www.drupaleasy.com/blogs/ultimike/2016/04/drupal-6-drupal-81x-custom-content-migration https://thinkshout.com/blog/2017/05/skipping-a-version-migrating-from-drupal-6-to-drupal-8-with-drupal-migrate/ @@ -27,3 +29,7 @@ https://evolvingweb.ca/blog/drupal-8-migration-migrating-taxonomy-term-reference [Migrating Drupal 7 redirects to Drupal 8](http://activelamp.com/blog/drupal/migrating-drupal-8-redirects/) [How to refresh new migrations in Drupal 8 migration module?](https://drupal.stackexchange.com/questions/191435/how-to-refresh-new-migrations-in-drupal-8-migration-module) + +[Drupal 8 Migrations: Taxonomy and Nodes](https://www.phase2technology.com/blog/drupal-8-migrations) + +[Migrating Content Translated with "Content Translation" from Drupal 7 to Drupal 8](https://evolvingweb.ca/blog/migrating-content-translated-content-translation-drupal-7-drupal-8) diff --git a/modules/custom/materio_migrate/src/Plugin/migrate/source/D7TaxonomyTermCompany.php b/modules/custom/materio_migrate/src/Plugin/migrate/source/D7TaxonomyTermCompany.php new file mode 100644 index 0000000..d2168fb --- /dev/null +++ b/modules/custom/materio_migrate/src/Plugin/migrate/source/D7TaxonomyTermCompany.php @@ -0,0 +1,104 @@ +select('taxonomy_term_data', 'td') + ->fields('td') + ->distinct() + ->orderBy('tid'); + $query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid'); + $query->addField('tv', 'machine_name'); + + if (isset($this->configuration['bundle'])) { + $query->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN'); + } + + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = [ + 'tid' => $this->t('The term ID.'), + 'vid' => $this->t('Existing term VID'), + 'machine_name' => $this->t('Vocabulary machine name'), + 'name' => $this->t('The name of the term.'), + 'description' => $this->t('The term description.'), + 'weight' => $this->t('Weight'), + 'parent' => $this->t("The Drupal term IDs of the term's parents."), + 'format' => $this->t("Format of the term description."), + ]; + return $fields; + } + + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + print("\n".'-- prepareRow -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')."\n"); + + // Get Field API field values. + foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) { + $tid = $row->getSourceProperty('tid'); + $row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid)); + } + + // Find parents for this row. + $parents = $this->select('taxonomy_term_hierarchy', 'th') + ->fields('th', ['parent', 'tid']) + ->condition('tid', $row->getSourceProperty('tid')) + ->execute() + ->fetchCol(); + $row->setSourceProperty('parent', $parents); + // print_r($parents); + + // If the term name or term description were replaced by real fields using + // the Drupal 7 Title module, use the fields value instead of the term name + // or term description. + // TODO: translations + if ($this->moduleExists('title')) { + $name_field = $row->getSourceProperty('name_field'); + // print_r($name_field); + if (isset($name_field[0]['value'])) { + $row->setSourceProperty('name', $name_field[0]['value']); + } + $description_field = $row->getSourceProperty('description_field'); + if (isset($description_field[0]['value'])) { + $row->setSourceProperty('description', $description_field[0]['value']); + } + } + + // TODO: tode node company + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['tid']['type'] = 'integer'; + return $ids; + } + +} diff --git a/modules/custom/materio_migrate/src/Plugin/migrate/source/D7TaxonomyTermShowroom.php b/modules/custom/materio_migrate/src/Plugin/migrate/source/D7TaxonomyTermShowroom.php new file mode 100644 index 0000000..084b234 --- /dev/null +++ b/modules/custom/materio_migrate/src/Plugin/migrate/source/D7TaxonomyTermShowroom.php @@ -0,0 +1,102 @@ +select('taxonomy_term_data', 'td') + ->fields('td') + ->distinct() + ->orderBy('tid'); + $query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid'); + $query->addField('tv', 'machine_name'); + + if (isset($this->configuration['bundle'])) { + $query->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN'); + } + + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = [ + 'tid' => $this->t('The term ID.'), + 'vid' => $this->t('Existing term VID'), + 'machine_name' => $this->t('Vocabulary machine name'), + 'name' => $this->t('The name of the term.'), + 'description' => $this->t('The term description.'), + 'weight' => $this->t('Weight'), + 'parent' => $this->t("The Drupal term IDs of the term's parents."), + 'format' => $this->t("Format of the term description."), + ]; + return $fields; + } + + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + print("\n".'-- prepareRow -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')."\n"); + + // Get Field API field values. + foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) { + $tid = $row->getSourceProperty('tid'); + $row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid)); + } + + // Find parents for this row. + $parents = $this->select('taxonomy_term_hierarchy', 'th') + ->fields('th', ['parent', 'tid']) + ->condition('tid', $row->getSourceProperty('tid')) + ->execute() + ->fetchCol(); + $row->setSourceProperty('parent', $parents); + // print_r($parents); + + // If the term name or term description were replaced by real fields using + // the Drupal 7 Title module, use the fields value instead of the term name + // or term description. + // TODO: translations + if ($this->moduleExists('title')) { + $name_field = $row->getSourceProperty('name_field'); + // print_r($name_field); + if (isset($name_field[0]['value'])) { + $row->setSourceProperty('name', $name_field[0]['value']); + } + $description_field = $row->getSourceProperty('description_field'); + if (isset($description_field[0]['value'])) { + $row->setSourceProperty('description', $description_field[0]['value']); + } + } + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['tid']['type'] = 'integer'; + return $ids; + } + +} diff --git a/modules/custom/materio_migrate/src/Plugin/migrate/source/D7TaxonomyTermTags.php b/modules/custom/materio_migrate/src/Plugin/migrate/source/D7TaxonomyTermTags.php new file mode 100644 index 0000000..c7d25ed --- /dev/null +++ b/modules/custom/materio_migrate/src/Plugin/migrate/source/D7TaxonomyTermTags.php @@ -0,0 +1,112 @@ +select('taxonomy_term_data', 'td') + ->fields('td') + ->distinct() + ->orderBy('tid'); + $query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid'); + $query->addField('tv', 'machine_name'); + + if (isset($this->configuration['bundle'])) { + $query->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN'); + } + + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = [ + 'tid' => $this->t('The term ID.'), + 'vid' => $this->t('Existing term VID'), + 'machine_name' => $this->t('Vocabulary machine name'), + 'name' => $this->t('The name of the term.'), + 'description' => $this->t('The term description.'), + 'weight' => $this->t('Weight'), + 'parent' => $this->t("The Drupal term IDs of the term's parents."), + 'format' => $this->t("Format of the term description."), + 'synonyms' => $this->t("Term's Synonyms (field : synonyms_synonym)"), + ]; + return $fields; + } + + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + print("\n\n".'-- prepareRow -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')."\n"); + + // Get Field API field values. + foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) { + $tid = $row->getSourceProperty('tid'); + $row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid)); + } + + // Find parents for this row. + $parents = $this->select('taxonomy_term_hierarchy', 'th') + ->fields('th', ['parent', 'tid']) + ->condition('tid', $row->getSourceProperty('tid')) + ->execute() + ->fetchCol(); + $row->setSourceProperty('parent', $parents); + // print_r($parents); + + // If the term name or term description were replaced by real fields using + // the Drupal 7 Title module, use the fields value instead of the term name + // or term description. + // TODO: translations + if ($this->moduleExists('title')) { + $name_field = $row->getSourceProperty('name_field'); + // print_r($name_field); + if (isset($name_field[0]['value'])) { + $row->setSourceProperty('name', $name_field[0]['value']); + } + $description_field = $row->getSourceProperty('description_field'); + if (isset($description_field[0]['value'])) { + $row->setSourceProperty('description', $description_field[0]['value']); + } + } + + // Synonyms + if ($this->moduleExists('title')) { + $synonyms = $row->getSourceProperty('synonyms_synonym'); + // print_r($synonyms); + if(!empty($synonyms)){ + $row->setSourceProperty('synonyms', $synonyms); + } + } + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['tid']['type'] = 'integer'; + return $ids; + } + +} diff --git a/modules/custom/materio_migrate/src/Plugin/migrate/source/D7TaxonomyTermThesaurus.php b/modules/custom/materio_migrate/src/Plugin/migrate/source/D7TaxonomyTermThesaurus.php new file mode 100644 index 0000000..010682d --- /dev/null +++ b/modules/custom/materio_migrate/src/Plugin/migrate/source/D7TaxonomyTermThesaurus.php @@ -0,0 +1,149 @@ +select('taxonomy_term_data', 'td') + ->fields('td') + ->distinct() + ->orderBy('tid'); + $query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid'); + $query->addField('tv', 'machine_name'); + + if (isset($this->configuration['bundle'])) { + $query->condition('tv.machine_name', (array) $this->configuration['bundle'], 'IN'); + } + + return $query; + } + + /** + * {@inheritdoc} + */ + public function fields() { + $fields = [ + 'tid' => $this->t('The term ID.'), + 'vid' => $this->t('Existing term VID'), + 'machine_name' => $this->t('Vocabulary machine name'), + 'name' => $this->t('The name of the term.'), + 'description' => $this->t('The term description.'), + 'weight' => $this->t('Weight'), + 'parent' => $this->t("The Drupal term IDs of the term's parents."), + 'format' => $this->t("Format of the term description."), + 'synonyms' => $this->t("Term's Synonyms (field : synonyms_synonym)"), + 'displayed_on_advanced_search' => $this->t("field_used_on_advanced_search"), + ]; + return $fields; + } + + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + print("\n\n".'-- prepareRow -- '.$row->getSourceProperty('tid')." -- ".$row->getSourceProperty('name')." -- ".$row->getSourceProperty('weight')."\n"); + + // Get Field API field values. + // foreach (array_keys($this->getFields('taxonomy_term', $row->getSourceProperty('machine_name'))) as $field) { + // $tid = $row->getSourceProperty('tid'); + // $row->setSourceProperty($field, $this->getFieldValues('taxonomy_term', $field, $tid)); + // print("field: ".$field."\n"); + // print_r($this->getFieldValues('taxonomy_term', $field, $tid)); + // print("-\n"); + // } + + // Find parents for this row. + $parents = $this->select('taxonomy_term_hierarchy', 'th') + ->fields('th', ['parent', 'tid']) + ->condition('tid', $row->getSourceProperty('tid')) + ->execute() + ->fetchCol(); + $row->setSourceProperty('parent', $parents); + // print_r($parents); + + // get the english term name as defaut + $query = $this->select('entity_translation', 'et') + // ->fields('et', [ + // 'entity_id', + // 'revision_id', + // 'language', + // 'source', + // 'uid', + // 'status', + // 'created', + // 'changed', + // ]) + // ->distinct() + ->condition('et.entity_type', 'taxonomy_term') + ->condition('et.language', 'en') + ->condition('rnf.language', 'en') + ->condition('et.entity_id', $row->getSourceProperty('tid')); + $query->innerjoin('field_revision_name_field', 'rnf', 'rnf.revision_id = et.revision_id'); + $query->fields('rnf', ['name_field_value']); + $name_field_en = $query->execute()->fetchField(); + + print($name_field_en); + + if($name_field_en != NULL && $name_field_en != ""){ + $row->setSourceProperty('name', $name_field_en); + } + + // If the term name or term description were replaced by real fields using + // the Drupal 7 Title module, use the fields value instead of the term name + // or term description. + // if ($this->moduleExists('title')) { + // $name_field = $row->getSourceProperty('name_field'); + // // print_r($name_field); + // if (isset($name_field[0]['value'])) { + // $row->setSourceProperty('name', $name_field[0]['value']); + // } + // $description_field = $row->getSourceProperty('description_field'); + // if (isset($description_field[0]['value'])) { + // $row->setSourceProperty('description', $description_field[0]['value']); + // } + // } + + // Synonyms + if ($this->moduleExists('title')) { + $synonyms = $row->getSourceProperty('synonyms_synonym'); + // print_r($synonyms); + if(!empty($synonyms)){ + $row->setSourceProperty('synonyms', $synonyms); + } + } + + // displayed_on_advanced_search + $advanced_search = $row->getSourceProperty('field_used_on_advanced_search'); + // print_r($advanced_search); + if(!empty($advanced_search)){ + $row->setSourceProperty('advanced_search', $advanced_search); + } + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function getIds() { + $ids['tid']['type'] = 'integer'; + return $ids; + } + +}