Skip to content

Commit

Permalink
header link settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AronNovak committed Jul 10, 2024
1 parent 23e2f5a commit 1cf5c60
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/install/islandora.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ broker_url: 'tcp://localhost:61613'
jwt_expiry: '+2 hour'
delete_media_and_files: TRUE
gemini_pseudo_bundles: []
allow_header_links: TRUE
3 changes: 3 additions & 0 deletions config/schema/islandora.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ islandora.settings:
jwt_expiry:
type: string
label: 'How long JWTs should last before expiring.'
allow_header_links:
type: boolean
label: 'Allow generating links in the HTTP header'
delete_media_and_files:
type: boolean
label: 'Node Delete with Media and Files'
Expand Down
14 changes: 13 additions & 1 deletion src/EventSubscriber/LinkHeaderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\islandora\EventSubscriber;

use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
Expand Down Expand Up @@ -72,6 +73,13 @@ abstract class LinkHeaderSubscriber implements EventSubscriberInterface {
*/
protected $utils;

/**
* Module settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $settings;

/**
* Constructor.
*
Expand All @@ -89,6 +97,8 @@ abstract class LinkHeaderSubscriber implements EventSubscriberInterface {
* Request stack (for current request).
* @param \Drupal\islandora\IslandoraUtils $utils
* Islandora utils.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* Config factory.
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
Expand All @@ -97,7 +107,8 @@ public function __construct(
AccountInterface $account,
RouteMatchInterface $route_match,
RequestStack $request_stack,
IslandoraUtils $utils
IslandoraUtils $utils,
ConfigFactoryInterface $config_factory
) {
$this->entityTypeManager = $entity_type_manager;
$this->entityFieldManager = $entity_field_manager;
Expand All @@ -108,6 +119,7 @@ public function __construct(
$this->account = $account;
$this->requestStack = $request_stack;
$this->utils = $utils;
$this->settings = $config_factory->get('islandora.settings');
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/EventSubscriber/MediaLinkHeaderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class MediaLinkHeaderSubscriber extends LinkHeaderSubscriber implements EventSub
* {@inheritdoc}
*/
public function onResponse(ResponseEvent $event) {
if (!$this->settings->get('allow_header_links')) {
return;
}
$response = $event->getResponse();

$media = $this->getObject($response, 'media');
Expand Down
3 changes: 3 additions & 0 deletions src/EventSubscriber/NodeLinkHeaderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class NodeLinkHeaderSubscriber extends LinkHeaderSubscriber implements EventSubs
* Event containing the response.
*/
public function onResponse(ResponseEvent $event) {
if (!$this->settings->get('allow_header_links')) {
return;
}
$response = $event->getResponse();

$node = $this->getObject($response, 'node');
Expand Down
9 changes: 9 additions & 0 deletions src/Form/IslandoraSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class IslandoraSettingsForm extends ConfigFormBase {
const GEMINI_PSEUDO_FIELD = 'field_gemini_uri';
const NODE_DELETE_MEDIA_AND_FILES = 'delete_media_and_files';
const REDIRECT_AFTER_MEDIA_SAVE = 'redirect_after_media_save';
const ALLOW_HEADER_LINKS = 'allow_header_links';

/**
* To list the available bundle types.
Expand Down Expand Up @@ -271,6 +272,13 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#url' => Url::fromRoute('system.jsonld_settings'),
];

$form[self::ALLOW_HEADER_LINKS] = [
'#type' => 'checkbox',
'#title' => $this->t('Allow header links'),
'#description' => $this->t('If checked, links in the HTTP header will be added'),
'#default_value' => (bool) $config->get(self::ALLOW_HEADER_LINKS),
];

return parent::buildForm($form, $form_state);
}

Expand Down Expand Up @@ -384,6 +392,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
->set(self::GEMINI_PSEUDO, $new_pseudo_types)
->set(self::NODE_DELETE_MEDIA_AND_FILES, $form_state->getValue(self::NODE_DELETE_MEDIA_AND_FILES))
->set(self::REDIRECT_AFTER_MEDIA_SAVE, $form_state->getValue(self::REDIRECT_AFTER_MEDIA_SAVE))
->set(self::ALLOW_HEADER_LINKS, $form_state->getValue(self::ALLOW_HEADER_LINKS))
->save();

parent::submitForm($form, $form_state);
Expand Down

0 comments on commit 1cf5c60

Please sign in to comment.