BlockRegion.php 1.23 KB
Newer Older
1
<?php
2

3 4
/**
 * @file
5
 * Contains \Drupal\block\Plugin\migrate\process\BlockRegion.
6 7
 */

8
namespace Drupal\block\Plugin\migrate\process;
9

10
use Drupal\migrate\MigrateExecutableInterface;
11 12 13 14 15
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
 * @MigrateProcessPlugin(
16
 *   id = "block_region"
17 18 19
 * )
 */
class BlockRegion extends ProcessPluginBase {
20

21 22 23 24 25 26
  /**
   * {@inheritdoc}
   *
   * Set the destination block region, based on the source region and theme as
   * well as the current destination default theme.
   */
27
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    list($region, $source_theme, $destination_theme) = $value;

    // Theme is the same on both source and destination, we will assume they
    // have the same regions.
    if (strtolower($source_theme) == strtolower($destination_theme)) {
      return $region;
    }

    // If the source and destination theme are different, try to use the
    // mappings defined in the configuration.
    $region_map = $this->configuration['region_map'];
    if (isset($region_map[$region])) {
      return $region_map[$region];
    }

    // Oh well, we tried. Put the block in the main content region.
    return 'content';
  }

}