4bc143fcdfd423f66756ad97baf15d41464a84ce
[yaffs-website] / Plugin / migrate / source / WineTerm.php
1 <?php
2
3 namespace Drupal\migrate_example_advanced\Plugin\migrate\source;
4
5 use Drupal\migrate\Plugin\migrate\source\SqlBase;
6
7 /**
8  * A straight-forward SQL-based source plugin, to retrieve category data from
9  * the source database.
10  *
11  * @MigrateSource(
12  *   id = "wine_term"
13  * )
14  */
15 class WineTerm extends SqlBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function query() {
21     return $this->select('migrate_example_advanced_categories', 'wc')
22       ->fields('wc', ['categoryid', 'type', 'name', 'details', 'category_parent', 'ordering'])
23       // This sort assures that parents are saved before children.
24       ->orderBy('category_parent', 'ASC');
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function fields() {
31     $fields = [
32       'categoryid' => $this->t('Unique ID of the category'),
33       'type' => $this->t('Category type corresponding to Drupal vocabularies'),
34       'name' => $this->t('Category name'),
35       'details' => $this->t('Description of the category'),
36       'category_parent' => $this->t('ID of the parent category'),
37       'ordering' => $this->t('Order in which to display this category'),
38     ];
39
40     return $fields;
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function getIds() {
47     return ['categoryid' => ['type' => 'integer']];
48   }
49
50 }