summaryrefslogtreecommitdiffstats
path: root/core/modules/content_translation/src/Plugin/migrate/source/d6/BlockTranslation.php
blob: f387b46de104b46bb007230bac54eec71520b3a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

namespace Drupal\content_translation\Plugin\migrate\source\d6;

use Drupal\block\Plugin\migrate\source\Block;

/**
 * Gets i18n block data from source database.
 *
 * @MigrateSource(
 *   id = "d6_block_translation",
 *   source_module = "i18nblocks"
 * )
 */
class BlockTranslation extends Block {

  /**
   * {@inheritdoc}
   */
  public function query() {
    // Let the parent set the block table to use, but do not use the parent
    // query. Instead build a query so can use a left join to the selected block
    // table.
    parent::query();
    $query = $this->select('i18n_blocks', 'i18n')
      ->fields('i18n', ['ibid', 'module', 'delta', 'type', 'language'])
      ->fields('b', ['bid', 'module', 'delta', 'theme', 'title']);
    $query->addField('b', 'module', 'block_module');
    $query->addField('b', 'delta', 'block_delta');
    $query->leftJoin($this->blockTable, 'b', ('b.module = i18n.module AND b.delta = i18n.delta'));
    return $query;
  }

  /**
   * {@inheritdoc}
   */
  public function fields() {
    $fields = parent::fields();
    $fields['language'] = $this->t('Language for this field.');
    return $fields;
  }

  /**
   * {@inheritdoc}
   */
  public function getIds() {
    $ids = parent::getIds();
    $ids['module']['alias'] = 'b';
    $ids['delta']['alias'] = 'b';
    $ids['language']['type'] = 'string';
    return $ids;
  }

}