"Fossies" - the Fresh Open Source Software Archive

Member "drupal-9.1.0-rc1/core/modules/taxonomy/src/Plugin/migrate/source/d6/Term.php" (18 Nov 2020, 1818 Bytes) of package /linux/www/drupal-9.1.0-rc1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Term.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\taxonomy\Plugin\migrate\source\d6;
    4 
    5 use Drupal\migrate\Row;
    6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
    7 
    8 /**
    9  * Taxonomy term source from database.
   10  *
   11  * @todo Support term_relation, term_synonym table if possible.
   12  *
   13  * @MigrateSource(
   14  *   id = "d6_taxonomy_term",
   15  *   source_module = "taxonomy"
   16  * )
   17  */
   18 class Term extends DrupalSqlBase {
   19 
   20   /**
   21    * {@inheritdoc}
   22    */
   23   public function query() {
   24     $query = $this->select('term_data', 'td')
   25       ->fields('td')
   26       ->distinct()
   27       ->orderBy('td.tid');
   28 
   29     if (isset($this->configuration['bundle'])) {
   30       $query->condition('td.vid', (array) $this->configuration['bundle'], 'IN');
   31     }
   32 
   33     return $query;
   34   }
   35 
   36   /**
   37    * {@inheritdoc}
   38    */
   39   public function fields() {
   40     $fields = [
   41       'tid' => $this->t('The term ID.'),
   42       'vid' => $this->t('Existing term VID'),
   43       'name' => $this->t('The name of the term.'),
   44       'description' => $this->t('The term description.'),
   45       'weight' => $this->t('Weight'),
   46       'parent' => $this->t("The Drupal term IDs of the term's parents."),
   47     ];
   48     if (isset($this->configuration['translations'])) {
   49       $fields['language'] = $this->t('The term language.');
   50       $fields['trid'] = $this->t('Translation ID.');
   51     }
   52     return $fields;
   53   }
   54 
   55   /**
   56    * {@inheritdoc}
   57    */
   58   public function prepareRow(Row $row) {
   59     // Find parents for this row.
   60     $parents = $this->select('term_hierarchy', 'th')
   61       ->fields('th', ['parent', 'tid'])
   62       ->condition('tid', $row->getSourceProperty('tid'))
   63       ->execute()
   64       ->fetchCol();
   65     $row->setSourceProperty('parent', $parents);
   66 
   67     return parent::prepareRow($row);
   68   }
   69 
   70   /**
   71    * {@inheritdoc}
   72    */
   73   public function getIds() {
   74     $ids['tid']['type'] = 'integer';
   75     return $ids;
   76   }
   77 
   78 }