Skip to content

Commit

Permalink
Merge pull request #130 from localgovdrupal/2.x
Browse files Browse the repository at this point in the history
2.3.2 release
  • Loading branch information
finnlewis authored Oct 2, 2023
2 parents f0304cb + d8e8121 commit 0304728
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
langcode: en
status: true
dependencies:
enforced:
module:
- localgov_subsites
- localgov_menu_link_group
id: localgov_menu_link_group_subsites
group_label: Subsites
weight: 0
parent_menu: admin
parent_menu_link: 'admin_toolbar_tools.extra_links:node.add'
child_menu_links:
- 'admin_toolbar_tools.extra_links:node.add.localgov_subsites_overview'
- 'admin_toolbar_tools.extra_links:node.add.localgov_subsites_page'
11 changes: 9 additions & 2 deletions src/Plugin/Block/SubsitesAbstractBlockBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ abstract class SubsitesAbstractBlockBase extends BlockBase implements ContainerF

use SubsitesHierarchyTrait;

/**
* Entity manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;

/**
* Node being displayed.
*
Expand Down Expand Up @@ -98,8 +105,8 @@ protected function getSubsiteBanner() {
*/
protected function blockAccess(AccountInterface $account) {
$this->node = $this->getContextValue('node');
if ($this->node and
($this->node->bundle() == 'localgov_subsites_overview' or $this->node->bundle() == 'localgov_subsites_page')
if ($this->node &&
($this->node->bundle() == 'localgov_subsites_overview' || $this->node->bundle() == 'localgov_subsites_page')
) {
return AccessResult::allowed();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Block/SubsitesBannerBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SubsitesBannerBlock extends SubsitesAbstractBlockBase {
public function build() {
$build = [];

if ($this->getSubsite($this->node)) {
if ($this->getSubsite()) {
if ($banner = $this->getSubsiteBanner()) {
$viewBuilder = $this->entityTypeManager->getViewBuilder('paragraph');
$build = $viewBuilder->view($banner);
Expand Down
4 changes: 3 additions & 1 deletion src/Plugin/Block/SubsitesNavigationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Template\Attribute;
use Drupal\Node\NodeInterface;
use Drupal\node\NodeInterface;

/**
* Class SubsiteNavigationBlock.
Expand Down Expand Up @@ -51,6 +51,8 @@ public function build() {
$cache = (new CacheableMetadata())->addCacheableDependency($subsite_entity);
$storage = $this->getNestedSetStorage('localgov_subsites');
$node = $this->getNestedSetNodeKeyFactory()->fromEntity($subsite_entity);
$subsite_id = NULL;
$overview_entity = NULL;
if ($ancestors = $storage->findAncestors($node)) {
$tree = $storage->findDescendants($ancestors[0]->getNodeKey());
array_unshift($tree, $ancestors[0]);
Expand Down
7 changes: 7 additions & 0 deletions src/Subsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
class Subsite implements ContainerInjectionInterface {
use SubsitesHierarchyTrait;

/**
* Entity manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;

/**
* Node being displayed.
*
Expand Down
1 change: 0 additions & 1 deletion tests/src/Functional/SubsitePagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ protected function setUp(): void {
'create localgov_subsites_overview content',

]);
$this->nodeStorage = $this->container->get('entity_type.manager')->getStorage('node');
}

/**
Expand Down

0 comments on commit 0304728

Please sign in to comment.