3 namespace Drupal\block\Plugin\migrate\source;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
9 * Drupal block source from database.
13 * source_provider = "block"
16 class Block extends DrupalSqlBase {
19 * The default theme name.
23 protected $defaultTheme;
26 * The admin theme name.
30 protected $adminTheme;
33 * Table containing block configuration.
37 protected $blockTable;
40 * Table mapping blocks to user roles.
44 protected $blockRoleTable;
47 * Table listing user roles.
51 protected $userRoleTable;
56 public function query() {
57 if ($this->getModuleSchemaVersion('system') >= 7000) {
58 $this->blockTable = 'block';
59 $this->blockRoleTable = 'block_role';
62 $this->blockTable = 'blocks';
63 $this->blockRoleTable = 'blocks_roles';
65 // Drupal 6 & 7 both use the same name for the user roles table.
66 $this->userRoleTable = 'role';
68 return $this->select($this->blockTable, 'b')->fields('b');
74 protected function initializeIterator() {
75 $this->defaultTheme = $this->variableGet('theme_default', 'Garland');
76 $this->adminTheme = $this->variableGet('admin_theme', NULL);
77 return parent::initializeIterator();
83 public function fields() {
85 'bid' => $this->t('The block numeric identifier.'),
86 'module' => $this->t('The module providing the block.'),
87 'delta' => $this->t('The block\'s delta.'),
88 'theme' => $this->t('Which theme the block is placed in.'),
89 'status' => $this->t('Whether or not the block is enabled.'),
90 'weight' => $this->t('Weight of the block for ordering within regions.'),
91 'region' => $this->t('Region the block is placed in.'),
92 'visibility' => $this->t('Visibility expression.'),
93 'pages' => $this->t('Pages list.'),
94 'title' => $this->t('Block title.'),
95 'cache' => $this->t('Cache rule.'),
102 public function getIds() {
103 $ids['module']['type'] = 'string';
104 $ids['delta']['type'] = 'string';
105 $ids['theme']['type'] = 'string';
112 public function prepareRow(Row $row) {
113 $row->setSourceProperty('default_theme', $this->defaultTheme);
114 $row->setSourceProperty('admin_theme', $this->adminTheme);
116 $module = $row->getSourceProperty('module');
117 $delta = $row->getSourceProperty('delta');
119 $query = $this->select($this->blockRoleTable, 'br')
120 ->fields('br', ['rid'])
121 ->condition('module', $module)
122 ->condition('delta', $delta);
123 $query->join($this->userRoleTable, 'ur', 'br.rid = ur.rid');
124 $roles = $query->execute()
126 $row->setSourceProperty('roles', $roles);
131 list($type, $id) = explode('-', $delta);
132 if ($type == 'feed') {
133 $item_count = $this->select('aggregator_feed', 'af')
134 ->fields('af', ['block'])
135 ->condition('fid', $id)
140 $item_count = $this->select('aggregator_category', 'ac')
141 ->fields('ac', ['block'])
142 ->condition('cid', $id)
146 $settings['aggregator']['item_count'] = $item_count;
149 $settings['book']['block_mode'] = $this->variableGet('book_block_mode', 'all pages');
152 $settings['forum']['block_num'] = $this->variableGet('forum_block_num_' . $delta, 5);
155 foreach (['statistics_block_top_day_num', 'statistics_block_top_all_num', 'statistics_block_top_last_num'] as $name) {
156 $settings['statistics'][$name] = $this->variableGet($name, 0);
163 $settings['user']['block_whois_new_count'] = $this->variableGet('user_block_whois_new_count', 5);
167 $settings['user']['block_seconds_online'] = $this->variableGet('user_block_seconds_online', 900);
168 $settings['user']['max_list_count'] = $this->variableGet('user_block_max_list_count', 10);
173 $row->setSourceProperty('settings', $settings);
174 return parent::prepareRow($row);