Commit 58fb8d25 authored by Lily Yan's avatar Lily Yan
Browse files

ISTWCMS-4532 Add services to remove 'This must be an external URL such as...

ISTWCMS-4532 Add services to remove 'This must be an external URL such as http://example.com' from the link field
parent ea7a7d0c
<?php
namespace Drupal\uw_ct_event\EventSubscriber;
use Drupal\field_event_dispatcher\Event\Field\WidgetFormAlterEvent;
use Drupal\hook_event_dispatcher\HookEventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class UwEventEventSubscriber.
*
* UW event event subscriber.
*
* @package Drupal\uw_ct_event\EventSubscriber
*/
class UwEventEventSubscriber implements EventSubscriberInterface {
/**
* Alter widget form.
*
* Remove 'This must be an external URL such as http://example.com' from the
* link field.
*
* @param \Drupal\field_event_dispatcher\Event\Field\WidgetFormAlterEvent $event
* The event.
*/
public function alterWidgetForm(WidgetFormAlterEvent $event): void {
$element = &$event->getElement();
// Only modify element 'Map' (field_uw_event_map).
if (isset($element['#title']) && $element['#title'] == "Map") {
$context = $event->getContext();
// When creating or editing an event node,
// remove 'This must be an external URL such as
// http://example.com' from the link field.
$forms = [
'node-uw-ct-event-form',
'node-uw-ct-event-edit-form',
];
if (in_array($context['form']['#attributes']['class'][0], $forms)) {
unset($element['uri']['#description']['#items'][1]);
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
HookEventDispatcherInterface::WIDGET_FORM_ALTER => 'alterWidgetForm',
];
}
}
services:
uw_ct_event.event_subscriber:
class: '\Drupal\uw_ct_event\EventSubscriber\UwEventEventSubscriber'
tags:
- { name: 'event_subscriber' }
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