Skip to content

Commit

Permalink
Merge pull request #5953 from WoltLab/get-form-field
Browse files Browse the repository at this point in the history
Make it easier to find a form field from a FormBuilder form
  • Loading branch information
BurntimeX authored Jul 3, 2024
2 parents 75059e3 + 6abcb11 commit 3773c84
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -783,4 +783,20 @@ public function validate()
$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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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).
Expand Down Expand Up @@ -410,4 +411,11 @@ public function showsSuccessMessage();
* @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;
}

0 comments on commit 3773c84

Please sign in to comment.