Skip to content
Snippets Groups Projects
Commit 25c2d536 authored by Lily Yan's avatar Lily Yan
Browse files

Merge branch 'feature/ISTWCMS-5680-ibiki-ohana-webform-migration-fix' into '1.1.x'

ISTWCMS-5680: Adding webform pre save fix for ohana branch.

See merge request !280
parents f2219a84 f753d52f
No related branches found
No related tags found
3 merge requests!280ISTWCMS-5680: Adding webform pre save fix for ohana branch.,!274Draft: ISTWCMS-5551: fixing office hours display,!260Feature/istwcms 5668 a5kulkar rename references to publications
<?php
namespace Drupal\uw_cfg_common\EventSubscriber;
use Drupal\core_event_dispatcher\EntityHookEvents;
use Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent;
use Drupal\webform\WebformInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Fixes roles permission for submission create for webforms.
*/
class UwWebformEventSubscriber implements EventSubscriberInterface {
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents(): array {
return [
EntityHookEvents::ENTITY_PRE_SAVE => 'preSave',
];
}
/**
* Entity pre save dispatched event.
*
* @param \Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent $event
* Event object.
*/
public function preSave(EntityPresaveEvent $event): void {
$entity = $event->getEntity();
if ($entity->bundle() === 'webform') {
/** @var \Drupal\webform\Entity\Webform $entity */
$access_rules = $entity->getAccessRules();
// Update webform submission access roles to be anonymous and
// authenticated. This will be done on EVERY webform save.
// Fixes migration issue with webforms. Once migration is updated and
// fixed, this code is no longer needed and can be removed.
$access_rules['create']['roles'] = [
'anonymous',
'authenticated',
];
$entity->setAccessRules($access_rules);
// Setting default access denied handler.
$entity->setSetting('form_access_denied', WebformInterface::ACCESS_DENIED_PAGE);
}
}
}
......@@ -45,3 +45,7 @@ services:
uw_cfg_common.missing_blocks:
class: Drupal\uw_cfg_common\Service\UWMissingBlocks
arguments: ['@entity_type.manager', '@keyvalue.expirable', '@layout_builder.tempstore_repository']
uw_cfg_common.webform.event_subscriber:
class: '\Drupal\uw_cfg_common\EventSubscriber\UwWebformEventSubscriber'
tags:
- { name: 'event_subscriber' }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment