Skip to content

Commit

Permalink
Fix WSOD on subsites when creating subsite page in front end theme (#155
Browse files Browse the repository at this point in the history
)

* Fix WSOD on subsites when creating subsite page in front end theme

Fix #154

Checks the entity ID is numeric (is not null) when trying to find subsite.
Adds a test to verify status code is 200 (500 without this fix).

* Change entity check from is_numeric to !is_null
  • Loading branch information
andybroomfield authored Aug 6, 2024
1 parent e1da568 commit 4392ae7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Plugin/Block/SubsitesHierarchyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ protected function getRootId(EntityInterface $entity): ?int {
'localgov_subsites_overview',
'localgov_subsites_page',
], TRUE)
&& !is_null($entity->id())
) {
if ($root_node = $this->getNestedSetStorage('localgov_subsites')->findRoot($this->getNestedSetNodeKeyFactory()->fromEntity($entity))) {
return $root_node->getId();
Expand Down
27 changes: 27 additions & 0 deletions tests/src/Functional/SubsiteBlocksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\TestFileCreationTrait;
use Symfony\Component\HttpFoundation\Response;

/**
* Tests user blocks.
Expand Down Expand Up @@ -66,7 +67,9 @@ protected function setUp(): void {
[
'administer blocks',
'create localgov_subsites_overview content',
'create localgov_subsites_page content',
'edit any localgov_subsites_overview content',
'edit any localgov_subsites_page content',
]
);
}
Expand Down Expand Up @@ -246,4 +249,28 @@ public function testSubsiteNavigationBlock() {
$this->assertSession()->pageTextNotContains($subsite_overview_title);
}

/**
* Test subsite blocks on node creation forms.
*
* This is for cases when using Mercury editor or page builders that use the
* front end theme.
*
* @see https://github.com/localgovdrupal/localgov_subsites/issues/154
*/
public function testSubsiteBlocksOnCreateNodePage() {

// Login and place blocks.
$this->drupalLogin($this->adminUser);
$this->drupalPlaceBlock('localgov_subsite_banner', ['region' => 'content']);
$this->drupalPlaceBlock('localgov_subsite_navigation');

// Check create new subsite overview page does not crash.
$this->drupalGet('/node/add/localgov_subsites_overview');
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);

// Check create new subsite page does not crash.
$this->drupalGet('/node/add/localgov_subsites_page');
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);
}

}

0 comments on commit 4392ae7

Please sign in to comment.