You are here

public function Block::prepareRow in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/block/src/Plugin/migrate/source/Block.php \Drupal\block\Plugin\migrate\source\Block::prepareRow()

Adds additional data to the row.

Parameters

\Drupal\migrate\Row $row: The row object.

Return value

bool FALSE if this row needs to be skipped.

Overrides SourcePluginBase::prepareRow

1 method overrides Block::prepareRow()
BlockTranslation::prepareRow in core/modules/block/src/Plugin/migrate/source/d6/BlockTranslation.php
Adds additional data to the row.

File

core/modules/block/src/Plugin/migrate/source/Block.php, line 112

Class

Block
Drupal block source from database.

Namespace

Drupal\block\Plugin\migrate\source

Code

public function prepareRow(Row $row) {
  $row
    ->setSourceProperty('default_theme', $this->defaultTheme);
  $row
    ->setSourceProperty('admin_theme', $this->adminTheme);
  $module = $row
    ->getSourceProperty('module');
  $delta = $row
    ->getSourceProperty('delta');
  $query = $this
    ->select($this->blockRoleTable, 'br')
    ->fields('br', [
    'rid',
  ])
    ->condition('module', $module)
    ->condition('delta', $delta);
  $query
    ->join($this->userRoleTable, 'ur', 'br.rid = ur.rid');
  $roles = $query
    ->execute()
    ->fetchCol();
  $row
    ->setSourceProperty('roles', $roles);
  $settings = [];
  switch ($module) {
    case 'aggregator':
      list($type, $id) = explode('-', $delta);
      if ($type == 'feed') {
        $item_count = $this
          ->select('aggregator_feed', 'af')
          ->fields('af', [
          'block',
        ])
          ->condition('fid', $id)
          ->execute()
          ->fetchField();
      }
      else {
        $item_count = $this
          ->select('aggregator_category', 'ac')
          ->fields('ac', [
          'block',
        ])
          ->condition('cid', $id)
          ->execute()
          ->fetchField();
      }
      $settings['aggregator']['item_count'] = $item_count;
      break;
    case 'book':
      $settings['book']['block_mode'] = $this
        ->variableGet('book_block_mode', 'all pages');
      break;
    case 'forum':
      $settings['forum']['block_num'] = $this
        ->variableGet('forum_block_num_' . $delta, 5);
      break;
    case 'statistics':
      foreach ([
        'statistics_block_top_day_num',
        'statistics_block_top_all_num',
        'statistics_block_top_last_num',
      ] as $name) {
        $settings['statistics'][$name] = $this
          ->variableGet($name, 0);
      }
      break;
    case 'user':
      switch ($delta) {
        case 2:
        case 'new':
          $settings['user']['block_whois_new_count'] = $this
            ->variableGet('user_block_whois_new_count', 5);
          break;
        case 3:
        case 'online':
          $settings['user']['block_seconds_online'] = $this
            ->variableGet('user_block_seconds_online', 900);
          $settings['user']['max_list_count'] = $this
            ->variableGet('user_block_max_list_count', 10);
          break;
      }
      break;
  }
  $row
    ->setSourceProperty('settings', $settings);
  return parent::prepareRow($row);
}