class RemoveXFrameOptionsSubscriber in Allow site iframing 8
Same name and namespace in other branches
- 3.0.x src/EventSubscriber/RemoveXFrameOptionsSubscriber.php \Drupal\allow_iframed_site\EventSubscriber\RemoveXFrameOptionsSubscriber
An event subscriber to remove the X-Frame-Options header.
Hierarchy
- class \Drupal\allow_iframed_site\EventSubscriber\RemoveXFrameOptionsSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of RemoveXFrameOptionsSubscriber
1 string reference to 'RemoveXFrameOptionsSubscriber'
1 service uses RemoveXFrameOptionsSubscriber
File
- src/
EventSubscriber/ RemoveXFrameOptionsSubscriber.php, line 15
Namespace
Drupal\allow_iframed_site\EventSubscriberView source
class RemoveXFrameOptionsSubscriber implements EventSubscriberInterface {
/**
* Array of Config options.
*
* @var array $config
*/
protected $config;
/**
* Condition manager.
*
* @var \Drupal\Core\Executable\ExecutableManagerInterface
*/
protected $conditionManager;
/**
* RemoveXFrameOptionsSubscriber constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* ConfigFactory.
* @param \Drupal\Core\Executable\ExecutableManagerInterface $condition_manager
* ConditionManager.
*/
public function __construct(ConfigFactoryInterface $config_factory, ExecutableManagerInterface $condition_manager) {
$this->config = $config_factory
->get('allow_iframed_site.settings');
$this->conditionManager = $condition_manager;
}
/**
* Remove the X-Frame-Options header.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
*
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
public function RemoveXFrameOptions(FilterResponseEvent $event) {
$xframe = TRUE;
foreach ($this->config
->getRawData() as $key => $config) {
try {
/* @var \Drupal\system\Plugin\Condition\RequestPath $condition */
$condition = $this->conditionManager
->createInstance($key);
$condition
->setConfiguration($this->config
->get($key));
if ($condition
->evaluate() && $condition
->isNegated() || !$condition
->evaluate() && !$condition
->isNegated()) {
$xframe = FALSE;
}
} catch (PluginException $exception) {
// Just ignore it, there's probably not much else to do.
}
}
// If we got here we should be fine, but check it anyway.
if ($xframe) {
$response = $event
->getResponse();
$response->headers
->remove('X-Frame-Options');
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::RESPONSE][] = [
'RemoveXFrameOptions',
-10,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RemoveXFrameOptionsSubscriber:: |
protected | property | Condition manager. | |
RemoveXFrameOptionsSubscriber:: |
protected | property | Array of Config options. | |
RemoveXFrameOptionsSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
RemoveXFrameOptionsSubscriber:: |
public | function | Remove the X-Frame-Options header. | |
RemoveXFrameOptionsSubscriber:: |
public | function | RemoveXFrameOptionsSubscriber constructor. |