Skip to content
Snippets Groups Projects
Unverified Commit 4a477027 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2404105 by chr.fritsch, jlbellido, penyaskito, alexpott: When a profile...

Issue #2404105 by chr.fritsch, jlbellido, penyaskito, alexpott: When a profile installs a block for a theme, it is created for all enabled themes
parent 1111de84
No related branches found
No related tags found
No related merge requests found
Showing
with 164 additions and 0 deletions
......@@ -6,6 +6,7 @@
*/
use Drupal\Component\Utility\Html;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
......@@ -86,8 +87,18 @@ function block_page_top(array &$page_top) {
*
* @param $theme_list
* An array of theme names.
*
* @see block_modules_installed()
*/
function block_themes_installed($theme_list) {
// Disable this functionality prior to install profile installation because
// block configuration is often optional or provided by the install profile
// itself. block_theme_initialize() will be called when the install profile is
// installed.
if (InstallerKernel::installationAttempted() && \Drupal::config('core.extension')->get('module.' . \Drupal::installProfile()) === NULL) {
return;
}
foreach ($theme_list as $theme) {
// Don't initialize themes that are not displayed in the UI.
if (\Drupal::service('theme_handler')->hasUi($theme)) {
......@@ -133,6 +144,24 @@ function block_theme_initialize($theme) {
}
}
/**
* Implements hook_modules_installed().
*
* @see block_themes_installed()
*/
function block_modules_installed($modules) {
// block_themes_installed() does not call block_theme_initialize() during site
// installation because block configuration can be optional or provided by the
// profile. Now, when the profile is installed, this configuration exists,
// call block_theme_initialize() for all installed themes.
$profile = \Drupal::installProfile();
if (in_array($profile, $modules, TRUE)) {
foreach (\Drupal::service('theme_handler')->listInfo() as $theme => $data) {
block_theme_initialize($theme);
}
}
}
/**
* Implements hook_rebuild().
*/
......
admin: testing_theme_optional_blocks
default: testing_theme_required_blocks
name: Testing themes blocks
type: profile
description: 'Minimal profile for testing block installation of themes.'
version: VERSION
hidden: true
themes:
- testing_theme_optional_blocks
- testing_theme_required_blocks
- testing_theme_without_blocks
install:
- block
langcode: en
status: true
dependencies:
theme:
- testing_theme_optional_blocks
id: testing_theme_optional_blocks_page_title
theme: testing_theme_optional_blocks
region: header
weight: -30
provider: null
plugin: page_title_block
settings:
id: page_title_block
label: 'Page title'
provider: core
label_display: '0'
visibility: { }
name: Testing theme with optional blocks
type: theme
base theme: false
package: Testing
version: VERSION
regions:
header: 'Header'
pre_content: 'Pre-content'
breadcrumb: Breadcrumb
highlighted: Highlighted
help: Help
content: Content
page_top: 'Page top'
page_bottom: 'Page bottom'
sidebar_first: 'First sidebar'
langcode: en
status: true
dependencies:
theme:
- testing_theme_required_blocks
id: testing_theme_required_blocks_account_menu
theme: testing_theme_required_blocks
region: secondary_menu
weight: -4
provider: null
plugin: system_menu_block:account
settings:
id: system_menu_block:account
label: 'User account menu'
provider: system
label_display: '0'
level: 1
depth: 1
expand_all_items: false
visibility: { }
name: Testing theme with required blocks
type: theme
base theme: false
package: Testing
version: VERSION
regions:
header: 'Header'
pre_content: 'Pre-content'
breadcrumb: Breadcrumb
highlighted: Highlighted
help: Help
content: Content
page_top: 'Page top'
page_bottom: 'Page bottom'
sidebar_first: 'First sidebar'
name: Testing theme without blocks
type: theme
base theme: false
package: Testing
version: VERSION
regions:
header: 'Header'
pre_content: 'Pre-content'
breadcrumb: Breadcrumb
highlighted: Highlighted
help: Help
content: Content
page_top: 'Page top'
page_bottom: 'Page bottom'
sidebar_first: 'First sidebar'
<?php
namespace Drupal\FunctionalTests\Installer;
use Drupal\block\Entity\Block;
/**
* Verifies that the installer does not generate theme blocks.
*
* @group Installer
*/
class InstallerThemesBlocksProfileTest extends InstallerTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'testing_theme_required_blocks';
/**
* {@inheritdoc}
*/
protected $profile = 'testing_themes_blocks';
/**
* Verify that there is no automatic block generation.
*/
public function testInstaller() {
// Account menu is a block that testing_theme_required_blocks provides,
// but not testing_theme_optional_blocks. There shouldn't be a account menu
// block for testing_theme_optional_blocks after the installation.
$this->assertEmpty(Block::load('testing_theme_optional_blocks_account_menu'));
$this->assertNotEmpty(Block::load('testing_theme_optional_blocks_page_title'));
// Ensure that for themes without blocks, some default blocks will be
// created.
$this->assertNotEmpty(Block::load('testing_theme_without_blocks_account_menu'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment