Skip to content
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
21 changes: 13 additions & 8 deletions src/Plugin/Block/PageHeaderBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\localgov_core\Plugin\views\display_extender\PageHeaderDisplayExtender;

/**
* Provides a 'PageHeaderBlock' block.
Expand Down Expand Up @@ -260,14 +261,18 @@ protected function getLede() {
if ($this->view instanceof ViewExecutable) {
$extender = $this->view->getDisplay()->getExtenders()['localgov_page_header_display_extender'] ?? NULL;

// Need to render view to apply tokens.
$this->view->render();
$lede = $extender->getLede();
return [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $lede,
];
// Only return a view lede if the Page Header Display extender is found.
if ($extender instanceof PageHeaderDisplayExtender) {

// Need to render view to apply tokens.
$this->view->render();
$lede = $extender->getLede();
return [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $lede,
];
}
}

return NULL;
Expand Down
25 changes: 24 additions & 1 deletion tests/src/Functional/ViewsPageExtenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
use Drupal\node\NodeInterface;
use Symfony\Component\HttpFoundation\Response;

/**
* Functional tests for LocalGovDrupal install profile.
Expand Down Expand Up @@ -38,7 +39,7 @@ protected function setUp(): void {
}

/**
* Test block display.
* Test view with the page header extender displays correctly.
*/
public function testViewWithPageHeadeExtender(): void {

Expand Down Expand Up @@ -67,4 +68,26 @@ public function testViewWithPageHeadeExtender(): void {

}

/**
* Test a view page displays even when the display extender is disabled.
*/
public function testViewWithoutPageExtenderInstalled(): void {

// Disable the pageHeaderExtender.
$config = \Drupal::service('config.factory')->getEditable('views.settings');
$display_extenders = $config->get('display_extenders') ?: [];
$display_extenders = array_filter($display_extenders, function ($item) {
return $item != 'localgov_page_header_display_extender' ? TRUE : FALSE;
});
$config->set('display_extenders', $display_extenders);
$config->save();

// Try to access the test view.
$this->drupalGet('/recent-content');

// Test view page should still display without the extender enabled.
// @See https://github.com/localgovdrupal/localgov_core/issues/270
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);
}

}
Loading