Add `LanguageItemFormNode`
authorMatthias Schmidt <gravatronics@live.com>
Sat, 12 Dec 2020 15:25:09 +0000 (16:25 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 12 Dec 2020 15:25:09 +0000 (16:25 +0100)
Close #3753

wcfsetup/install/files/lib/system/form/builder/LanguageItemFormNode.class.php [new file with mode: 0644]

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 (file)
index 0000000..ccc74f5
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+namespace wcf\system\form\builder;
+use wcf\system\WCF;
+
+/**
+ * Form node that shows a language item without any surrounding HTML code.
+ * 
+ * @author      Matthias Schmidt
+ * @copyright   2001-2020 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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;
+       }
+}