function BlockCustomTranslation::query

Same name in other branches
  1. 9 core/modules/block_content/src/Plugin/migrate/source/d7/BlockCustomTranslation.php \Drupal\block_content\Plugin\migrate\source\d7\BlockCustomTranslation::query()
  2. 8.9.x core/modules/block_content/src/Plugin/migrate/source/d7/BlockCustomTranslation.php \Drupal\block_content\Plugin\migrate\source\d7\BlockCustomTranslation::query()
  3. 11.x core/modules/block_content/src/Plugin/migrate/source/d7/BlockCustomTranslation.php \Drupal\block_content\Plugin\migrate\source\d7\BlockCustomTranslation::query()

Overrides SqlBase::query

File

core/modules/block_content/src/Plugin/migrate/source/d7/BlockCustomTranslation.php, line 35

Class

BlockCustomTranslation
Drupal 7 i18n content block translations source from database.

Namespace

Drupal\block_content\Plugin\migrate\source\d7

Code

public function query() {
    // Build a query based on blockCustomTable table where each row has the
    // translation for only one property, either title or description. The
    // method prepareRow() is then used to obtain the translation for the
    // other property.
    $query = $this->select(static::CUSTOM_BLOCK_TABLE, 'b')
        ->fields('b', [
        'bid',
        'format',
        'body',
    ])
        ->fields('i18n', [
        'property',
    ])
        ->fields('lt', [
        'lid',
        'translation',
        'language',
    ])
        ->orderBy('b.bid');
    // Use 'title' for the info field to match the property name in
    // i18nStringTable.
    $query->addField('b', 'info', 'title');
    // Add in the property, which is either title or body. Cast the bid to text
    // so PostgreSQL can make the join.
    $query->leftJoin(static::I18N_STRING_TABLE, 'i18n', '[i18n].[objectid] = CAST([b].[bid] AS CHAR(255))');
    $query->condition('i18n.type', 'block');
    // Add in the translation for the property.
    $query->innerJoin('locales_target', 'lt', '[lt].[lid] = [i18n].[lid]');
    return $query;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.