Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header link settings #1038

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
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
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An update hook should be implemented to create/populate this new configuration value when updating existing installations.

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
4 changes: 2 additions & 2 deletions islandora.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ services:
- { name: event_subscriber }
islandora.media_link_header_subscriber:
class: Drupal\islandora\EventSubscriber\MediaLinkHeaderSubscriber
arguments: ['@entity_type.manager', '@entity_field.manager', '@access_manager', '@current_user', '@current_route_match', '@request_stack', '@islandora.utils']
arguments: ['@entity_type.manager', '@entity_field.manager', '@access_manager', '@current_user', '@current_route_match', '@request_stack', '@islandora.utils', '@config.factory']
tags:
- { name: event_subscriber }
islandora.node_link_header_subscriber:
class: Drupal\islandora\EventSubscriber\NodeLinkHeaderSubscriber
arguments: ['@entity_type.manager', '@entity_field.manager', '@access_manager', '@current_user', '@current_route_match', '@request_stack', '@islandora.utils']
arguments: ['@entity_type.manager', '@entity_field.manager', '@access_manager', '@current_user', '@current_route_match', '@request_stack', '@islandora.utils', '@config.factory']
tags:
- { name: event_subscriber }
islandora.admin_view_route_subscriber:
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
Loading