-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenAPI UI Hook to Event Subscriber (#16552)
* convert hook to event subscriber * correct doc block * remove libraries definition * convert one event subscriber to another * remove composer requirements no longer needed --------- Co-authored-by: Tanner Heffner <[email protected]>
- Loading branch information
1 parent
d2d3982
commit 73a8a63
Showing
4 changed files
with
55 additions
and
20 deletions.
There are no files selected for viewing
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
46 changes: 46 additions & 0 deletions
46
docroot/modules/custom/va_gov_api/src/EventSubscriber/AddJsEventSubscriber.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,46 @@ | ||
<?php | ||
|
||
namespace Drupal\va_gov_api\EventSubscriber; | ||
|
||
use Drupal\core_event_dispatcher\Event\Theme\PageAttachmentsEvent; | ||
use Drupal\core_event_dispatcher\PageHookEvents; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
|
||
/** | ||
* Add JS to the OpenAPI UI selector page so only one schema is displayed. | ||
*/ | ||
class AddJsEventSubscriber implements EventSubscriberInterface { | ||
|
||
/** | ||
* The request. | ||
*/ | ||
protected RequestStack $requestStack; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct(RequestStack $requestStack) { | ||
$this->requestStack = $requestStack; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents(): array { | ||
return [ | ||
PageHookEvents::PAGE_ATTACHMENTS => ['onPageAttachments'], | ||
]; | ||
} | ||
|
||
/** | ||
* Modify response to add JS script to a route. | ||
*/ | ||
public function onPageAttachments(PageAttachmentsEvent $event): void { | ||
if ($this->requestStack->getCurrentRequest()->get('_route') === 'openapi.downloads') { | ||
$attachments = &$event->getAttachments(); | ||
$attachments['#attached']['library'][] = 'va_gov_api/json_schemas_table_filter'; | ||
} | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# Increases the # of items in the response for any given jsonapi request. | ||
parameters: | ||
next_jsonapi.size_max: 2000 | ||
services: | ||
va_gov_api.add_js_to_ui: | ||
class: Drupal\va_gov_api\EventSubscriber\AddJsEventSubscriber | ||
arguments: ['@request_stack'] | ||
tags: | ||
- { name: event_subscriber } |