From 638ceb9350cd4c6567badca4d9620bb062b959db Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 12 Dec 2020 16:25:09 +0100 Subject: [PATCH] Add `LanguageItemFormNode` Close #3753 --- .../builder/LanguageItemFormNode.class.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/form/builder/LanguageItemFormNode.class.php diff --git a/wcfsetup/install/files/lib/system/form/builder/LanguageItemFormNode.class.php b/wcfsetup/install/files/lib/system/form/builder/LanguageItemFormNode.class.php new file mode 100644 index 0000000000..ccc74f5f15 --- /dev/null +++ b/wcfsetup/install/files/lib/system/form/builder/LanguageItemFormNode.class.php @@ -0,0 +1,81 @@ + + * @package WoltLabSuite\Core\System\Form\Builder + * @since 5.4 + */ +class LanguageItemFormNode implements IFormChildNode { + use TFormChildNode; + use TFormNode; + + /** + * language item shown in the form node + * @var null|string + */ + protected $languageItem; + + /** + * template variables passed to the language item + * @var array + */ + protected $variables = []; + + /** + * @inheritDoc + */ + public function getHtml() { + return WCF::getLanguage()->getDynamicVariable($this->getLanguageItem(), $this->getVariables()); + } + + /** + * Returns the name of the language item shown in the form node. + * + * @throws \BadMethodCallException if language iten has not been set yet + */ + public function getLanguageItem(): string { + if ($this->languageItem === null) { + throw new \BadMethodCallException("Language item has not been set yet."); + } + + return $this->languageItem; + } + + /** + * Returns the template variables passed to the language item. + */ + public function getVariables(): array { + return $this->variables; + } + + /** + * Sets the language item shown in the form node and returns this form node. + */ + public function languageItem(string $languageItem): self { + $this->languageItem = $languageItem; + + return $this; + } + + /** + * @inheritDoc + */ + public function validate() { + // does nothing + } + + /** + * Sets the template variables passed to the language item and returns this form node. + */ + public function variables(array $variables): self { + $this->variables = $variables; + + return $this; + } +} -- 2.20.1