Skip to content

Commit 4392ae7

Browse files
Fix WSOD on subsites when creating subsite page in front end theme (#155)
* 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
1 parent e1da568 commit 4392ae7

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Plugin/Block/SubsitesHierarchyTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ protected function getRootId(EntityInterface $entity): ?int {
114114
'localgov_subsites_overview',
115115
'localgov_subsites_page',
116116
], TRUE)
117+
&& !is_null($entity->id())
117118
) {
118119
if ($root_node = $this->getNestedSetStorage('localgov_subsites')->findRoot($this->getNestedSetNodeKeyFactory()->fromEntity($entity))) {
119120
return $root_node->getId();

tests/src/Functional/SubsiteBlocksTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Drupal\Tests\BrowserTestBase;
1212
use Drupal\Tests\node\Traits\NodeCreationTrait;
1313
use Drupal\Tests\TestFileCreationTrait;
14+
use Symfony\Component\HttpFoundation\Response;
1415

1516
/**
1617
* Tests user blocks.
@@ -66,7 +67,9 @@ protected function setUp(): void {
6667
[
6768
'administer blocks',
6869
'create localgov_subsites_overview content',
70+
'create localgov_subsites_page content',
6971
'edit any localgov_subsites_overview content',
72+
'edit any localgov_subsites_page content',
7073
]
7174
);
7275
}
@@ -246,4 +249,28 @@ public function testSubsiteNavigationBlock() {
246249
$this->assertSession()->pageTextNotContains($subsite_overview_title);
247250
}
248251

252+
/**
253+
* Test subsite blocks on node creation forms.
254+
*
255+
* This is for cases when using Mercury editor or page builders that use the
256+
* front end theme.
257+
*
258+
* @see https://github.com/localgovdrupal/localgov_subsites/issues/154
259+
*/
260+
public function testSubsiteBlocksOnCreateNodePage() {
261+
262+
// Login and place blocks.
263+
$this->drupalLogin($this->adminUser);
264+
$this->drupalPlaceBlock('localgov_subsite_banner', ['region' => 'content']);
265+
$this->drupalPlaceBlock('localgov_subsite_navigation');
266+
267+
// Check create new subsite overview page does not crash.
268+
$this->drupalGet('/node/add/localgov_subsites_overview');
269+
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);
270+
271+
// Check create new subsite page does not crash.
272+
$this->drupalGet('/node/add/localgov_subsites_page');
273+
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);
274+
}
275+
249276
}

0 commit comments

Comments
 (0)