Skip to content

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

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

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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);
}

}