class BlockTheme

Same name and namespace in other branches
  1. 9 core/modules/block/src/Plugin/migrate/process/BlockTheme.php \Drupal\block\Plugin\migrate\process\BlockTheme
  2. 8.9.x core/modules/block/src/Plugin/migrate/process/BlockTheme.php \Drupal\block\Plugin\migrate\process\BlockTheme
  3. 11.x core/modules/block/src/Plugin/migrate/process/BlockTheme.php \Drupal\block\Plugin\migrate\process\BlockTheme

Hierarchy

Expanded class hierarchy of BlockTheme

1 file declares its use of BlockTheme
BlockThemeDeprecationTest.php in core/modules/block/tests/src/Unit/Plugin/migrate/process/BlockThemeDeprecationTest.php

File

core/modules/block/src/Plugin/migrate/process/BlockTheme.php, line 14

Namespace

Drupal\block\Plugin\migrate\process
View source
class BlockTheme extends ProcessPluginBase implements ContainerFactoryPluginInterface {
  
  /**
   * Contains the system.theme configuration object.
   */
  protected Config $themeConfig;
  
  /**
   * List of themes available on the destination.
   *
   * @var string[]
   */
  protected array $themes;
  
  /**
   * Constructs a BlockTheme object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin ID for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Config\Config|\Drupal\migrate\Plugin\MigrationInterface $theme_config
   *   The system.theme configuration factory object.
   * @param string[]|\Drupal\Core\Config\Config $themes
   *   The list of themes available on the destination.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, Config|MigrationInterface $theme_config, array|Config $themes) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    if ($theme_config instanceof MigrationInterface) {
      @trigger_error('Calling ' . __CLASS__ . '::__construct() with the $migration argument is deprecated in drupal:10.1.0 and is removed in drupal:11.0.0. See https://www.drupal.org/node/3323212', E_USER_DEPRECATED);
      $theme_config = func_get_arg(4);
      $themes = func_get_arg(5);
    }
    $this->themeConfig = $theme_config;
    $this->themes = $themes;
  }
  
  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container->get('config.factory')
      ->get('system.theme'), $container->get('theme_handler')
      ->listInfo());
  }
  
  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    [
      $theme,
      $default_theme,
      $admin_theme,
    ] = $value;
    // If the source theme exists on the destination, we're good.
    if (isset($this->themes[$theme])) {
      return $theme;
    }
    // If the source block is assigned to a region in the source default theme,
    // then assign it to the destination default theme.
    if (strtolower($theme) == strtolower($default_theme)) {
      return $this->themeConfig
        ->get('default');
    }
    // If the source block is assigned to a region in the source admin theme,
    // then assign it to the destination admin theme.
    if ($admin_theme && strtolower($theme) == strtolower($admin_theme)) {
      return $this->themeConfig
        ->get('admin');
    }
    // We couldn't map it to a D8 theme so just return the incoming theme.
    return $theme;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
BlockTheme::$themeConfig protected property Contains the system.theme configuration object.
BlockTheme::$themes protected property List of themes available on the destination.
BlockTheme::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
BlockTheme::transform public function Performs the associated process. Overrides ProcessPluginBase::transform
BlockTheme::__construct public function Constructs a BlockTheme object.
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 6
PluginInspectionInterface::getPluginId public function Gets the plugin ID of the plugin instance. 2
ProcessPluginBase::$stopPipeline protected property Determines if processing of the pipeline is stopped.
ProcessPluginBase::isPipelineStopped public function Determines if the pipeline should stop processing. Overrides MigrateProcessInterface::isPipelineStopped
ProcessPluginBase::multiple public function Indicates whether the returned value requires multiple handling. Overrides MigrateProcessInterface::multiple 3
ProcessPluginBase::reset public function Resets the internal data of a plugin. Overrides MigrateProcessInterface::reset
ProcessPluginBase::stopPipeline protected function Stops pipeline processing after this plugin finishes.

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