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
13 changes: 12 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"require": {
"drupal/field_group": "^3.1",
"drupal/image_widget_crop": "^2.3",
"drupal/linkit": "^6.0-beta1",
"drupal/linkit": "^6.1 || ^7.0",
"drupal/media_library_edit": "^3.0",
"drupal/metatag": "^2.0.2",
"drupal/pathauto": "^1.8",
Expand All @@ -23,6 +23,17 @@
"composer-exit-on-patch-failure": true,
"patchLevel": {
"drupal/core": "-p2"
},
"patches": {
"drupal/field_group": {
"Nullable types #3490746": "https://git.drupalcode.org/project/field_group/-/commit/23540687517e3afee192f08f1c32a40d69f2dfa7.patch"
},
"drupal/paragraphs": {
"Nullable types #3492419": "https://git.drupalcode.org/project/paragraphs/-/commit/9efaadd62448fc847f9860a2066d81c3039daa07.patch"
},
"drupal/role_delegation": {
"Nullable types #3499682": "https://git.drupalcode.org/project/role_delegation/-/commit/f21be7a1f66de4a095c1398d9a53aa44bdad3524.patch"
}
}
}
}
9 changes: 9 additions & 0 deletions config/schema/localgov_core.views.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
views.display_extender.localgov_page_header_display_extender:
type: views_display_extender
mapping:
lede:
type: text
label: 'Lede'
tokenize:
type: boolean
label: 'Should replacement tokens be used from the first row'
3 changes: 2 additions & 1 deletion localgov_core.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ name: LocalGov Core
description: LocalGov Drupal helper functions and core dependencies.
package: LocalGov Drupal
type: module
core_version_requirement: ^10.1
core_version_requirement: ^10.1 || ^11

dependencies:
- drupal:block
- drupal:field
- drupal:node
- drupal:views
- field_group:field_group

test_dependencies:
Expand Down
25 changes: 25 additions & 0 deletions localgov_core.install
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

use Drupal\localgov_core\FieldRenameHelper;

/**
* Implements hook_install().
*/
function localgov_core_install(): void {
_localgov_core_enabled_views_page_display_extender();
}

/**
* Update Field names for localgov_core provided fields.
*
Expand Down Expand Up @@ -95,3 +102,21 @@ function localgov_core_update_8004() {
// Save the configuration.
$config->save();
}

/**
* Enables the views page header display extender.
*/
function localgov_core_update_8005(): void {
_localgov_core_enabled_views_page_display_extender();
}

/**
* Enable localgov_page_header_display_extender plugin.
*/
function _localgov_core_enabled_views_page_display_extender(): void {
$config = \Drupal::service('config.factory')->getEditable('views.settings');
$display_extenders = $config->get('display_extenders') ?: [];
$display_extenders[] = 'localgov_page_header_display_extender';
$config->set('display_extenders', $display_extenders);
$config->save();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: LocalGov Admin Theme Improvements
type: module
description: 'Small items to fix issues with the admin theme.'
package: LocalGov Drupal
core_version_requirement: ^9 || ^10
core_version_requirement: ^10 || ^11
2 changes: 1 addition & 1 deletion modules/localgov_media/localgov_media.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: LocalGov Media
description: LocalGov Media configuration.
package: LocalGov Drupal
type: module
core_version_requirement: ^9 || ^10
core_version_requirement: ^10 || ^11

dependencies:
- drupal:ckeditor5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class StandardProfileTest extends BrowserTestBase {
protected $profile = 'standard';

/**
* Test locagov_media installs with the Standard profile.
* Test localgov_media installs with the Standard profile.
*/
public function testEnablingLocalGovMedia() {

\Drupal::service('module_installer')->install(['localgov_media']);
$this->assertTrue(\Drupal::service('module_handler')->moduleExists('localgov_media'));
}

}
2 changes: 1 addition & 1 deletion modules/localgov_roles/localgov_roles.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: LocalGov Roles
description: Default user roles.
package: LocalGov Drupal
type: module
core_version_requirement: ^9 || ^10
core_version_requirement: ^10 || ^11

dependencies:
- drupal:path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ name: 'LocalGov Roles Test Helper 1'
type: module
description: 'Support module for LocalGov Roles tests'
package: Testing
core_version_requirement: ^9 || ^10
core_version_requirement: ^10 || ^11
hidden: true
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ name: 'LocalGov Roles Test Helper 2'
type: module
description: 'Support module for LocalGov Roles tests'
package: Testing
core_version_requirement: ^9 || ^10
core_version_requirement: ^10 || ^11
hidden: true
46 changes: 44 additions & 2 deletions src/Event/PageHeaderDisplayEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Drupal\localgov_core\Event;

use Drupal\Component\EventDispatcher\Event;
use Drupal\Core\Entity\EntityInterface;
use Drupal\views\ViewExecutable;

/**
* Event that is fired when displaying the page header.
Expand All @@ -18,6 +20,13 @@ class PageHeaderDisplayEvent extends Event {
*/
protected $entity = NULL;

/**
* View executable associated with the current route.
*
* @var \Drupal\views\ViewExecutable|null
*/
protected $view = NULL;

/**
* The page lede override.
*
Expand Down Expand Up @@ -56,7 +65,10 @@ class PageHeaderDisplayEvent extends Event {
/**
* {@inheritdoc}
*/
public function __construct($entity) {
public function __construct($entity = NULL) {
// @todo remove the $entity paramater or deprecate it.
// Since we should use the setters and getters.
// Or we can mark this class as internal?
$this->entity = $entity;
}

Expand All @@ -66,10 +78,40 @@ public function __construct($entity) {
* @return \Drupal\Core\Entity\EntityInterface|null
* The entity.
*/
public function getEntity() {
public function getEntity() : ?EntityInterface {
return $this->entity;
}

/**
* Entity setter.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity.
*/
public function setEntity(EntityInterface $entity) : void {
$this->entity = $entity;
}

/**
* View getter.
*
* @return \Drupal\views\ViewExecutable|null
* The view.
*/
public function getView() : ?ViewExecutable {
return $this->view;
}

/**
* View setter.
*
* @param \Drupal\views\ViewExecutable $view
* The view.
*/
public function setView(ViewExecutable $view) : void {
$this->view = $view;
}

/**
* Lede getter.
*
Expand Down
56 changes: 51 additions & 5 deletions src/Plugin/Block/PageHeaderBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\localgov_core\Plugin\Block;

use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
Expand All @@ -14,7 +13,10 @@
use Drupal\localgov_core\Event\PageHeaderDisplayEvent;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
use Drupal\views\ViewExecutable;
use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RequestStack;

/**
Expand All @@ -37,7 +39,7 @@ class PageHeaderBlock extends BlockBase implements ContainerFactoryPluginInterfa
/**
* Core event_dispatcher service.
*
* @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;

Expand All @@ -62,6 +64,13 @@ class PageHeaderBlock extends BlockBase implements ContainerFactoryPluginInterfa
*/
protected $entity = NULL;

/**
* View executable associated with the current route.
*
* @var \Drupal\views\ViewExecutable|null
*/
protected $view = NULL;

/**
* The page title override.
*
Expand Down Expand Up @@ -115,7 +124,7 @@ public static function create(ContainerInterface $container, array $configuratio
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, CurrentRouteMatch $current_route_match, ContainerAwareEventDispatcher $event_dispatcher, RequestStack $request_stack, TitleResolver $title_resolver) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, CurrentRouteMatch $current_route_match, EventDispatcherInterface $event_dispatcher, RequestStack $request_stack, TitleResolver $title_resolver) {
parent::__construct($configuration, $plugin_id, $plugin_definition);

$this->currentRouteMatch = $current_route_match;
Expand All @@ -130,6 +139,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
$route = $this->currentRouteMatch->getRouteObject();
if (!is_null($route)) {
$parameters = $route->getOption('parameters');
$defaults = $route->getDefaults();
if (!is_null($parameters)) {
foreach ($parameters as $name => $options) {
if (!isset($options['type'])) {
Expand All @@ -152,10 +162,31 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
}
}
}

// If this is a view path, set the view instead.
if (isset($defaults['view_id']) && isset($defaults['display_id'])) {
$view = Views::getView($defaults['view_id']);
if ($view) {
$view->setDisplay($defaults['display_id']);
$this->view = $view;
}
}
}

// Dispatch event to allow modules to alter block content.
$event = new PageHeaderDisplayEvent($this->entity);
$event = new PageHeaderDisplayEvent();

// If an entity is set, pass to the event.
if ($this->entity instanceof EntityInterface) {
$event->setEntity($this->entity);
}

// If a view is set, pass to the event.
if ($this->view instanceof ViewExecutable) {
$event->setView($this->view);
}

// Dispatch event.
$this->eventDispatcher->dispatch($event, PageHeaderDisplayEvent::EVENT_NAME);

// Set the title, lede, visibility and cache tags.
Expand All @@ -164,7 +195,8 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
$this->lede = is_null($event->getLede()) ? $this->getLede() : $event->getLede();
$this->visible = $event->getVisibility();
$entityCacheTags = is_null($this->entity) ? [] : $this->entity->getCacheTags();
$this->cacheTags = is_null($event->getCacheTags()) ? $entityCacheTags : $event->getCacheTags();
$viewCacheTags = is_null($this->view) ? [] : $this->view->getCacheTags();
$this->cacheTags = is_null($event->getCacheTags()) ? array_merge($entityCacheTags, $viewCacheTags) : $event->getCacheTags();
}

/**
Expand Down Expand Up @@ -224,6 +256,20 @@ protected function getLede() {
];
}

// Return view custom summary.
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,
];
}

return NULL;
}

Expand Down
Loading