From: Marcel Werk Date: Wed, 3 Jul 2024 12:04:26 +0000 (+0200) Subject: Make it easier to find a form field from a FormBuilder form X-Git-Tag: 6.1.0_Alpha_1~43^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6abcb11b545a28a30e3138bec1c2782527988fae;p=GitHub%2FWoltLab%2FWCF.git Make it easier to find a form field from a FormBuilder form Basically, it is just a wrapper around `getNodeById()`, which also checks whether it is a `IFormField`. --- diff --git a/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php b/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php index b792e0e9c4..f712156760 100644 --- a/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php @@ -783,4 +783,20 @@ class FormDocument implements IFormDocument $this->traitValidate(); } } + + /** + * @inheritDoc + */ + public function getFormField(string $nodeId): ?IFormField + { + $node = $this->getNodeById($nodeId); + if ($node === null) { + return null; + } + if (!($node instanceof IFormField)) { + return null; + } + + return $node; + } } diff --git a/wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php b/wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php index 973df89323..666929524b 100644 --- a/wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php @@ -5,6 +5,7 @@ namespace wcf\system\form\builder; use wcf\data\IStorableObject; use wcf\system\form\builder\button\IFormButton; use wcf\system\form\builder\data\IFormDataHandler; +use wcf\system\form\builder\field\IFormField; /** * Represents a "whole" form (document). @@ -410,4 +411,11 @@ interface IFormDocument extends IFormParentNode * @throws \InvalidArgumentException if the given form mode is invalid */ public function successMessage($languageItem = null, array $variables = []); + + /** + * Returns the form field with the given id or `null` if no such field exists. + * + * @since 6.1 + */ + public function getFormField(string $nodeId): ?IFormField; }