c361588efc65198a600331f7d178975ccb283c5b
[yaffs-website] / web / core / modules / contact / src / Plugin / migrate / source / ContactCategory.php
1 <?php
2
3 namespace Drupal\contact\Plugin\migrate\source;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7
8 /**
9  * Contact category source from database.
10  *
11  * @MigrateSource(
12  *   id = "contact_category",
13  *   source_module = "contact"
14  * )
15  */
16 class ContactCategory extends DrupalSqlBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function query() {
22     $query = $this->select('contact', 'c')
23       ->fields('c', [
24         'cid',
25         'category',
26         'recipients',
27         'reply',
28         'weight',
29         'selected',
30       ]
31     );
32     $query->orderBy('c.cid');
33     return $query;
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function prepareRow(Row $row) {
40     $row->setSourceProperty('recipients', explode(',', $row->getSourceProperty('recipients')));
41     return parent::prepareRow($row);
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function fields() {
48     return [
49       'cid' => $this->t('Primary Key: Unique category ID.'),
50       'category' => $this->t('Category name.'),
51       'recipients' => $this->t('Comma-separated list of recipient email addresses.'),
52       'reply' => $this->t('Text of the auto-reply message.'),
53       'weight' => $this->t("The category's weight."),
54       'selected' => $this->t('Flag to indicate whether or not category is selected by default. (1 = Yes, 0 = No)'),
55     ];
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function getIds() {
62     $ids['cid']['type'] = 'integer';
63     return $ids;
64   }
65
66 }