From 67f97df0b35773e4a7f12f8b2c2ed885055e746c Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 17 Jun 2021 07:39:26 +0200 Subject: [PATCH] Update event listener GUI validation to consider new `IEvent` interface --- ...istenerPackageInstallationPlugin.class.php | 32 ++++++++++++++++++- wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php index 5506fb61cb..c16611495e 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/EventListenerPackageInstallationPlugin.class.php @@ -10,6 +10,7 @@ use wcf\system\devtools\pip\IDevtoolsPipEntryList; use wcf\system\devtools\pip\IGuiPackageInstallationPlugin; use wcf\system\devtools\pip\TXmlGuiPackageInstallationPlugin; use wcf\system\event\EventHandler; +use wcf\system\event\IEvent; use wcf\system\event\listener\IParameterizedEventListener; use wcf\system\form\builder\container\FormContainer; use wcf\system\form\builder\field\BooleanFormField; @@ -264,7 +265,36 @@ class EventListenerPackageInstallationPlugin extends AbstractXMLPackageInstallat ->objectProperty('listenerclassname') ->label('wcf.acp.pip.eventListener.listenerClassName') ->required() - ->implementedInterface(IParameterizedEventListener::class), + ->addValidator(new FormFieldValidator('callable', function (ClassNameFormField $formField) { + $listenerClassName = $formField->getValue(); + /** @var TextFormField $eventClassNameField */ + $eventClassNameField = $formField->getDocument()->getNodeById('eventClassName'); + $eventClassName = $eventClassNameField->getValue(); + + if (\is_subclass_of($eventClassName, IEvent::class)) { + if (!is_callable(new $listenerClassName)) { + $formField->addValidationError( + new FormFieldValidationError( + 'noCallable', + 'wcf.acp.pip.eventListener.listenerClassName.error.noCallable', + [ + 'listenerClassName' => $listenerClassName, + ] + ) + ); + } + } elseif (!\is_subclass_of($listenerClassName, IParameterizedEventListener::class)) { + $formField->addValidationError( + new FormFieldValidationError( + 'interface', + 'wcf.form.field.className.error.interface', + [ + 'interface' => IParameterizedEventListener::class, + ] + ) + ); + } + })), SingleSelectionFormField::create('environment') ->label('wcf.acp.pip.eventListener.environment') diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 1bd69fa451..0f0eb03307 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2372,6 +2372,7 @@ Die Datenbestände werden sorgfältig gepflegt, aber es ist nicht ausgeschlossen + {$listenerClassName} hat keine __invoke()-Methode.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 658b49c14c..502e959642 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2358,6 +2358,7 @@ If you have already bought the licenses for the listed apps, th :default]]> + {$listenerClassName} does not have a __invoke() method.]]> user), the ACP (admin), or in both (all).]]> -- 2.20.1