l10n_server-2.x-dev/l10n_migrate/src/Plugin/migrate/source/L10nServerGroup.php

l10n_migrate/src/Plugin/migrate/source/L10nServerGroup.php
<?php

declare(strict_types=1);

namespace Drupal\l10n_migrate\Plugin\migrate\source;

use Drupal\Core\Database\Query\SelectInterface;
use Drupal\migrate\Plugin\migrate\source\SqlBase;

/**
 * Migrate Source plugin.
 *
 * @MigrateSource(
 *   id = "l10n_migrate_server_group",
 *   source_module = "l10n_migrate",
 * )
 */
class L10nServerGroup extends SqlBase {

  /**
   * {@inheritdoc}
   */
  public function query(): SelectInterface {
    $query = $this
      ->select('node', 'n');
    $query
      ->innerJoin('l10n_groups_group', 'g', 'n.nid = g.nid');
    $query
      ->innerJoin('field_data_og_description', 'd', 'n.nid = d.entity_id');
    $query
      ->innerJoin('field_data_body', 'b', 'n.nid = b.entity_id');
    $query
      ->condition('n.type', 'l10n_group');
    $query
      ->fields('n', [
        'nid', 'vid', 'type', 'language', 'title', 'uid', 'status', 'created', 'changed', 'comment', 'promote', 'sticky', 'tnid', 'translate',
      ]);
    $query->fields('g', [
      'language',
    ]);
    $query->fields('d', [
      'og_description_value',
    ]);
    $query->fields('b', [
      'body_value',
    ]);
    $query
      ->addExpression('g.language', 'og_language');
    $query
      ->addExpression('d.og_description_value', 'og_description');
    $query
      ->addExpression('b.body_value', 'og_welcome');

    return $query;
  }

  /**
   * {@inheritdoc}
   */
  public function fields(): array {
    return [
      'nid' => $this->t('Node ID'),
      'vid' => $this->t('Release ID'),
      'type' => $this->t('Type'),
      'language' => $this->t('Language'),
      'title' => $this->t('Title'),
      'uid' => $this->t('User ID'),
      'status' => $this->t('Status'),
      'created' => $this->t('Created'),
      'changed' => $this->t('Changed'),
      'comment' => $this->t('Comment'),
      'promote' => $this->t('Promote'),
      'sticky' => $this->t('Sticky'),
      'tnid' => $this->t('TNID'),
      'translate' => $this->t('Translate'),
      'og_language' => $this->t('Group language'),
      'og_description' => $this->t('Group description'),
      'og_welcome' => $this->t('Group welcome'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getIds(): array {
    return [
      'nid' => [
        'type' => 'integer',
        'alias' => 'n',
      ],
    ];
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc