diff --git a/config/localgov/block.publication_in_page_navigation.yml b/config/localgov/block.publication_in_page_navigation.yml new file mode 100644 index 0000000..7662257 --- /dev/null +++ b/config/localgov/block.publication_in_page_navigation.yml @@ -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 diff --git a/config/localgov/block.publication_navigation.yml b/config/localgov/block.publication_navigation.yml new file mode 100644 index 0000000..aa7b25d --- /dev/null +++ b/config/localgov/block.publication_navigation.yml @@ -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 diff --git a/config/localgov/block.publication_page_header_block.yml b/config/localgov/block.publication_page_header_block.yml new file mode 100644 index 0000000..3056fe3 --- /dev/null +++ b/config/localgov/block.publication_page_header_block.yml @@ -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 diff --git a/localgov_publications.install b/localgov_publications.install index d7b93d8..71b5220 100644 --- a/localgov_publications.install +++ b/localgov_publications.install @@ -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; @@ -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(); } /** @@ -66,130 +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, TRUE)) { - $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); - $regions = array_keys($themeInfo->info['regions']); - - foreach ($blocks as $block) { - - if (!in_array($block['region'], $regions, TRUE)) { - 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 = []; - - $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. *