protected function FixtureBase::installTheme in Lightning Core 8.3
Same name and namespace in other branches
- 8.5 tests/src/FixtureBase.php \Drupal\Tests\lightning_core\FixtureBase::installTheme()
- 8.4 tests/src/FixtureBase.php \Drupal\Tests\lightning_core\FixtureBase::installTheme()
Installs a theme if not already present.
Parameters
string $theme: The machine name of the theme to install.
1 call to FixtureBase::installTheme()
- FixtureContext::setUp in tests/
src/ FixtureContext.php - @BeforeScenario
File
- tests/
src/ FixtureBase.php, line 189
Class
- FixtureBase
- Base class for contexts which set up and tear down a complete test fixture.
Namespace
Drupal\Tests\lightning_coreCode
protected function installTheme($theme) {
if ($this->container
->get('theme_handler')
->themeExists($theme)) {
return;
}
elseif ($this->container
->get('theme_installer')
->install([
$theme,
])) {
array_push($this->themes, $theme);
// This works around a weird hole in the theme extension system. Normally,
// when a theme is installed, the Block module will react by copying the
// blocks from the current default theme into the newly installed theme.
// However, if it can't determine which region the copied blocks should be
// placed into, it will set them to a blank region and disable them (this
// behavior is enforced by the Block entity class's preSave() method too).
// It seems that, in the context of this fixture class, the block system
// gets incorrect information from the theme system, which causes the
// blocks not to be copied or set up correctly. So we need to do all that.
if ($this->container
->get('module_handler')
->moduleExists('block')) {
// Copy blocks from the default theme. For whatever reason, the theme
// system will be unable to read the list of regions from the theme
// extension system (generally due to the fact that the extension system
// is so massively awful), so the blocks are copied into limbo (i.e.,
// disabled and in the '' region).
block_theme_initialize($theme);
// Load the copied blocks.
$blocks = $this->container
->get('entity_type.manager')
->getStorage('block')
->loadByProperties([
'theme' => $theme,
'region' => '',
'status' => FALSE,
]);
/** @var \Drupal\block\BlockInterface $block */
foreach ($blocks as $block) {
// Use the config system to edit the blocks directly, since the whole
// limbo thing is enforced by Block::preSave().
$this->container
->get('config.factory')
->getEditable($block
->getConfigDependencyName())
->set('region', 'content')
->set('status', TRUE)
->save();
}
}
}
}