Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved default blocks to use the new mechanism for placing them in localgov_core #184

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions config/localgov/block.publication_in_page_navigation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugin: localgov_publications_toc_block
region: sidebar_first
weight: 1
settings:
label: 'On this page'
label_display: visible
provider: localgov_publications
context_mapping:
node: '@node.node_route_context:node'
visibility:
'entity_bundle:node':
id: 'entity_bundle:node'
negate: false
context_mapping:
node: '@node.node_route_context:node'
bundles:
localgov_publication_page: localgov_publication_page
17 changes: 17 additions & 0 deletions config/localgov/block.publication_navigation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugin: publication_navigation
region: sidebar_first
weight: 0
settings:
label: 'Publication navigation'
label_display: visible
provider: localgov_publications
context_mapping:
node: '@node.node_route_context:node'
visibility:
'entity_bundle:node':
id: 'entity_bundle:node'
negate: false
context_mapping:
node: '@node.node_route_context:node'
bundles:
localgov_publication_page: localgov_publication_page
18 changes: 18 additions & 0 deletions config/localgov/block.publication_page_header_block.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugin: localgov_publications_page_header_block
region: content_top
weight: -6
settings:
label: 'Publications page header block.'
label_display: '0'
provider: localgov_publications
context_mapping:
node: '@node.node_route_context:node'
visibility:
'entity_bundle:node':
id: 'entity_bundle:node'
negate: false
context_mapping:
node: '@node.node_route_context:node'
bundles:
localgov_publication_cover_page: localgov_publication_cover_page
localgov_publication_page: localgov_publication_page
127 changes: 0 additions & 127 deletions localgov_publications.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* Install, update and uninstall functions for the LocalGov Publications module.
*/

use Drupal\block\Entity\Block;
use Drupal\filter\Entity\FilterFormat;
use Drupal\filter\FilterFormatInterface;

Expand All @@ -16,7 +15,6 @@ function localgov_publications_install() {
localgov_publications_install_book_settings();
localgov_publications_install_pathauto_settings();
localgov_publications_install_filter();
localgov_publications_install_blocks();
}

/**
Expand Down Expand Up @@ -66,131 +64,6 @@ function localgov_publications_install_filter(): void {
$wysiwygFormat->save();
}

/**
* Installs this module's default blocks.
*/
function localgov_publications_install_blocks(): void {

$activeTheme = \Drupal::service('theme.manager')->getActiveTheme()->getName();

/** @var \Drupal\Core\Extension\ThemeHandlerInterface $themeHandler */
$themeHandler = \Drupal::service('theme_handler');

$themes = ['localgov_base', 'localgov_scarfolk'];

if (!in_array($activeTheme, $themes)) {
$themes[] = $activeTheme;
}

$blocks = localgov_publications_install_block_definitions();

// Loop over every theme and block definition, so we set up all the blocks in
// all the relevant themes.
foreach ($themes as $theme) {

// Get info about the theme, so we can check we're placing blocks into
// regions that actually exist.
$themeInfo = $themeHandler->getTheme($theme);
if (empty($themeInfo)) {
continue;
}
$regions = array_keys($themeInfo->info['regions']);

foreach ($blocks as $block) {

if (!in_array($block['region'], $regions)) {
continue;
}

$block['id'] = $theme . '_' . $block['plugin'];
$block['theme'] = $theme;

Block::create($block)->save();
}
}
}

/**
* Block definitions for localgov_publications_install_blocks().
*/
function localgov_publications_install_block_definitions(): array {

$blocks[] = [
'plugin' => 'localgov_publications_page_header_block',
'region' => 'content_top',
'settings' => [
'label' => 'Publications page header block.',
'label_display' => '0',
'context_mapping' => [
'node' => '@node.node_route_context:node',
],
],
'visibility' => [
'entity_bundle:node' => [
'id' => 'entity_bundle:node',
'context_mapping' => [
'node' => '@node.node_route_context:node',
],
'bundles' => [
'localgov_publication_cover_page' => 'localgov_publication_cover_page',
'localgov_publication_page' => 'localgov_publication_page',
],
],
],
'weight' => -100,
];

$blocks[] = [
'plugin' => 'publication_navigation',
'region' => 'sidebar_first',
'settings' => [
'label' => 'Publication navigation',
'label_display' => 'visible',
'context_mapping' => [
'node' => '@node.node_route_context:node',
],
],
'visibility' => [
'entity_bundle:node' => [
'id' => 'entity_bundle:node',
'context_mapping' => [
'node' => '@node.node_route_context:node',
],
'bundles' => [
'localgov_publication_page' => 'localgov_publication_page',
],
],
],
'weight' => 0,
];

$blocks[] = [
'plugin' => 'localgov_publications_toc_block',
'region' => 'sidebar_first',
'settings' => [
'label' => 'On this page',
'label_display' => 'visible',
'context_mapping' => [
'node' => '@node.node_route_context:node',
],
],
'visibility' => [
'entity_bundle:node' => [
'id' => 'entity_bundle:node',
'context_mapping' => [
'node' => '@node.node_route_context:node',
],
'bundles' => [
'localgov_publication_page' => 'localgov_publication_page',
],
],
],
'weight' => 1,
];

return $blocks;
}

/**
* Fixes error messages after this module is installed.
*
Expand Down
Loading