-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EWPP-2570: Add EventSubscriber to alter created/updated facets.
- Loading branch information
1 parent
0a45edf
commit 7e08d36
Showing
7 changed files
with
157 additions
and
4 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
modules/oe_list_pages_open_vocabularies/oe_list_pages_open_vocabularies.services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
modules/oe_list_pages_open_vocabularies/src/Event/SearchApiConfigurationEvents.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\oe_list_pages_open_vocabularies\Event; | ||
|
||
/** | ||
* Update Search API configuration. | ||
* | ||
* @internal | ||
*/ | ||
final class SearchApiConfigurationEvents { | ||
|
||
/** | ||
* Event update search API facet configuration. | ||
*/ | ||
const UPDATE_SEARCH_API_FACET = 'oe_list_pages_open_vocabularies.update_search_api_facet_config'; | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
modules/oe_list_pages_open_vocabularies/src/Event/SearchApiFacetUpdateEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\oe_list_pages_open_vocabularies\Event; | ||
|
||
use Drupal\facets\FacetInterface; | ||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
/** | ||
* Event for updating search api facet configuration. | ||
*/ | ||
class SearchApiFacetUpdateEvent extends Event { | ||
|
||
/** | ||
* The facet. | ||
* | ||
* @var \Drupal\facets\FacetInterface | ||
*/ | ||
protected FacetInterface $facet; | ||
|
||
/** | ||
* SearchApiFacetUpdateEvent constructor. | ||
*/ | ||
public function __construct(FacetInterface $facet) { | ||
$this->facet = $facet; | ||
} | ||
|
||
/** | ||
* Return the facet object. | ||
* | ||
* @return \Drupal\facets\FacetInterface | ||
* The facet object instance. | ||
*/ | ||
public function getFacet(): FacetInterface { | ||
return $this->facet; | ||
} | ||
|
||
/** | ||
* Set the updated facet object. | ||
* | ||
* @param \Drupal\facets\FacetInterface $facet | ||
* The facet object instance. | ||
* | ||
* @return $this | ||
*/ | ||
public function setFacet(FacetInterface $facet): SearchApiFacetUpdateEvent { | ||
$this->facet = $facet; | ||
return $this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...es/oe_list_pages_open_vocabularies_test/oe_list_pages_open_vocabularies_test.services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
services: | ||
oe_list_pages_open_vocabularies_test.config_subscriber: | ||
class: Drupal\oe_list_pages_open_vocabularies_test\EventSubscriber\SearchApiFacetTestSubscriber | ||
arguments: ['@oe_list_pages_open_vocabularies.configurator', '@entity_type.manager'] | ||
tags: | ||
- { name: event_subscriber } |
41 changes: 41 additions & 0 deletions
41
...oe_list_pages_open_vocabularies_test/src/EventSubscriber/SearchApiFacetTestSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Drupal\oe_list_pages_open_vocabularies_test\EventSubscriber; | ||
|
||
use Drupal\oe_list_pages_open_vocabularies\Event\SearchApiConfigurationEvents; | ||
use Drupal\oe_list_pages_open_vocabularies\Event\SearchApiFacetUpdateEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Responds to changes to facet configuration update/create. | ||
*/ | ||
class SearchApiFacetTestSubscriber implements EventSubscriberInterface { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents() { | ||
$events[SearchApiConfigurationEvents::UPDATE_SEARCH_API_FACET] = 'onFacetUpdate'; | ||
return $events; | ||
} | ||
|
||
/** | ||
* Updates the open vocabulary facets before saving. | ||
* | ||
* @param \Drupal\oe_list_pages_open_vocabularies\Event\SearchApiFacetUpdateEvent $event | ||
* The Search API Facet update event. | ||
*/ | ||
public function onFacetUpdate(SearchApiFacetUpdateEvent $event) { | ||
$facet = $event->getFacet(); | ||
$settings = [ | ||
'behavior' => 'text', | ||
'text' => 'No results found for this block!', | ||
'text_format' => 'plain_text', | ||
]; | ||
$facet->setEmptyBehavior($settings); | ||
$event->setFacet($facet); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters