Commit 7e64ed50 authored by Dave Lane's avatar Dave Lane
Browse files

update to improve consistency, but still not valid code

parent d2a6d39b
# Allow H5P embed # Allow H5P embed
Allows a Drupal 8 site offering a library of H5P (https://h5p.org) learning objects for external embedding, we need to override Drupal 8's default X-Frame-Options header to allow remote sites to embed. For a Drupal8 site offering a library of H5P (https://h5p.org) learning objects for external embedding, we need to override Drupal8's default X-Frame-Options header setting of "SAMEORIGIN" which prohibits embedding content. So, only in the case of H5P objects, which have a path starting with /h5p/[ID]/embed, we remove that header.
\ No newline at end of file
name: Allow H5P Object embedding name: Allow H5P Embed
description: For a Drupal8 site offering a library of H5P (https://h5p.org) learning objects for external embedding, we need to override Drupal8's default X-Frame-Options header setting of "SAMEORIGIN" which prohibits embedding content. So, only in the case of H5P objects, which have a path starting with /h5p/[ID]/embed, we remove that header. description: Allow external sites to embed H5P learning objects created and/or hosted on this site.
package: OERu Custom package: OERu
type: module type: module
core: 8.x core: 8.x
dependencies: dependencies:
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
* @file * @file
* H5P hooks that allows content to be submitted and viewed on the site. * H5P hooks that allows content to be submitted and viewed on the site.
*/ */
/*
// Prepare autoloading of dependencies // Prepare autoloading of dependencies
require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';
use Drupal\AllowH5PEmbed; use Drupal\AllowH5PEmbed;
*/
services: services:
remove_x_frame_options_subscriber: allow_h5p_embed.subscriber:
class: Drupal\mymodule\EventSubscriber\RemoveXFrameOptionsSubscriber class: Drupal\AllowH5PEmbed\EventSubscriber\RemoveXFrameOptionsSubscriber
tags: tags:
- { name: event_subscriber } - { name: event_subscriber }
<?php <?php
namespace Drupal\mymodule\EventSubscriber; namespace Drupal\AllowH5PEmbed\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
...@@ -9,14 +9,17 @@ use Symfony\Component\HttpKernel\KernelEvents; ...@@ -9,14 +9,17 @@ use Symfony\Component\HttpKernel\KernelEvents;
class RemoveXFrameOptionsSubscriber implements EventSubscriberInterface { class RemoveXFrameOptionsSubscriber implements EventSubscriberInterface {
public function RemoveXFrameOptions(FilterResponseEvent $event) { public function RemoveXFrameOptions(FilterResponseEvent $event) {
error_log('in RemoveXFrameOptions! Path: '.$event->getRequest()->getPathInfo());
$response = $event->getResponse(); $response = $event->getResponse();
if (preg_match('/^\/h5p\/[0-9]+\/embed$/', $event->getRequest()->getPathInfo())) { if (preg_match('/^\/h5p\/[0-9]+\/embed$/', $event->getRequest()->getPathInfo())) {
error_log('removing X-Frame-Options header');
$response->headers->remove('X-Frame-Options'); $response->headers->remove('X-Frame-Options');
} }
} }
public static function getSubscribedEvents() { public static function getSubscribedEvents() {
error_log('getting Subscribed Events');
$events[KernelEvents::RESPONSE][] = array('RemoveXFrameOptions', -10); $events[KernelEvents::RESPONSE][] = array('RemoveXFrameOptions', -10);
return $events; return $events;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment