phoneUtils = PhoneNumberUtil::getInstance(); $this->countryManager = $country_manager; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { return new static( $configuration, $plugin_id, $plugin_definition, $migration, $container->get('state'), $container->get('entity.manager'), $container->get('country_manager') ); } /** * {@inheritdoc} */ public function query() { $query = $this->select('taxonomy_term_data', 'td') ->fields('td') ->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."), 'revision_id' => $this->t('Revision ID'), 'language' => $this->t('Term translation language'), 'source' => $this->t('Term translation source language'), 'public_phone' => $this->t('Public phone converted to new format (with libphonenumber)') ]; return $fields; } /** * {@inheritdoc} */ public function prepareRow(Row $row) { $language = $row->getSourceProperty('language'); $tid = $row->getSourceProperty('tid'); drush_print('-- '.$language.' -- '.$tid." -- ".$row->getSourceProperty('name')." -- ".$row->getSourceProperty('weight')); // vocabulary machine name $machine_name = $row->getSourceProperty('machine_name'); $revid = $row->getSourceProperty('revision_id'); // Get Field API field values. foreach ($this->getFields('taxonomy_term', $machine_name) as $field_name => $field) { // Ensure we're using the right language if the entity is translatable. $field_language = $field['translatable'] ? $language : NULL; $row->setSourceProperty($field_name, $this->getFieldValues('taxonomy_term', $field_name, $tid, $revid, $field_language)); } // 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); // If the node title was replaced by a real field using the Drupal 7 Title // module, use the field value instead of the node title. if ($this->moduleExists('title')) { $name_field = $row->getSourceProperty('name_field'); if (isset($name_field[0]['value'])) { $row->setSourceProperty('name', $name_field[0]['value']); } } // get the tode nid $tode_nid = $this->select('field_data_field_tode_company', 'tode') ->condition('entity_type', 'node') ->condition('field_tode_company_tid', $tid) ->fields('tode', ['entity_id']) ->execute()->fetchField(); // drush_print('tode_nid: '.$tode_nid); // get the tode fields foreach ($this->getFields('node', 'company') as $field_name => $field) { // Ensure we're using the right language if the entity is translatable. $field_language = $field['translatable'] ? $language : NULL; $field_values = $this->getFieldValues('node', $field_name, $tode_nid, null, $field_language); drush_print($field_name.': '); print_r($field_values); $row->setSourceProperty($field_name, $field_values); } // make sure that feild_website url is absolute $field_website = $row->getSourceProperty('field_website'); if(isset($field_website[0]['url'])){ $url = $field_website[0]['url']; if(!strpos($url, 'http://')){ $field_website[0]['url'] = 'http://'.$url; $row->setSourceProperty('field_website', $field_website); } } // convert phone field with libphonenumber $field_phone = $row->getSourceProperty('field_public_phone'); if(isset($field_phone[0]['number']) && !empty($field_phone[0]['number'])){ $national_number = $field_phone[0]['number']; $region = strtoupper($field_phone[0]['country_codes']); $number = $this->phoneUtils->parse($national_number, $region); $row->setSourceProperty('public_phone', $this->phoneUtils->format($number, PhoneNumberFormat::E164)); } return parent::prepareRow($row); } /** * {@inheritdoc} */ public function getIds() { $ids['tid']['type'] = 'integer'; return $ids; } }