Version 1
[yaffs-website] / web / core / modules / action / src / Plugin / migrate / source / Action.php
1 <?php
2
3 namespace Drupal\action\Plugin\migrate\source;
4
5 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
6 use Drupal\migrate\Row;
7
8 /**
9  * Drupal action source from database.
10  *
11  * @MigrateSource(
12  *   id = "action",
13  *   source_provider = "system"
14  * )
15  */
16 class Action extends DrupalSqlBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function query() {
22     return $this->select('actions', 'a')
23       ->fields('a');
24   }
25
26   /**
27    * {@inheritdoc}
28    */
29   public function fields() {
30     $fields = [
31       'aid' => $this->t('Action ID'),
32       'type' => $this->t('Module'),
33       'callback' => $this->t('Callback function'),
34       'parameters' => $this->t('Action configuration'),
35     ];
36     if ($this->getModuleSchemaVersion('system') >= 7000) {
37       $fields['label'] = $this->t('Label of the action');
38     }
39     else {
40       $fields['description'] = $this->t('Action description');
41     }
42     return $fields;
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function getIds() {
49     $ids['aid']['type'] = 'string';
50     return $ids;
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public function prepareRow(Row $row) {
57     $aid = $row->getSourceProperty('aid');
58     if (is_numeric($aid)) {
59       if ($this->getModuleSchemaVersion('system') >= 7000) {
60         $label = $row->getSourceProperty('label');
61       }
62       else {
63         $label = $row->getSourceProperty('description');
64       }
65       $row->setSourceProperty('aid', $label);
66     }
67   }
68
69 }