Unverified Commit 2f070fc3 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

(cherry picked from commit 4a477027)
parent a5c24191
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -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().
 */
+2 −0
Original line number Diff line number Diff line
admin: testing_theme_optional_blocks
default: testing_theme_required_blocks
+11 −0
Original line number Diff line number Diff line
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
+17 −0
Original line number Diff line number Diff line
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: {  }
+15 −0
Original line number Diff line number Diff line
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'
Loading