Add CheckboxFormField (#3812)
authorPeter Lohse <github@hsrvmail.net>
Fri, 18 Dec 2020 18:17:12 +0000 (19:17 +0100)
committerGitHub <noreply@github.com>
Fri, 18 Dec 2020 18:17:12 +0000 (19:17 +0100)
* added implementation of a checkbox form field for boolen values

* fixed indentation

* added __checkboxFormField to syncTemplates.json

* added missing comma

com.woltlab.wcf/templates/__checkboxFormField.tpl [new file with mode: 0644]
syncTemplates.json
wcfsetup/install/files/acp/templates/__checkboxFormField.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/system/form/builder/field/CheckboxFormField.class.php [new file with mode: 0644]

diff --git a/com.woltlab.wcf/templates/__checkboxFormField.tpl b/com.woltlab.wcf/templates/__checkboxFormField.tpl
new file mode 100644 (file)
index 0000000..af2e22d
--- /dev/null
@@ -0,0 +1,14 @@
+<dl id="{@$field->getPrefixedId()}Container" {if !$field->getClasses()|empty} class="{implode from=$field->getClasses() item='class' glue=' '}{$class}{/implode}"{/if}{foreach from=$field->getAttributes() key='attributeName' item='attributeValue'} {$attributeName}="{$attributeValue}"{/foreach}{if !$field->checkDependencies()} style="display: none;"{/if}>
+       <dt></dt>
+       <dd>
+               <label>
+                       <input type="checkbox" id="{@$field->getPrefixedId()}" name="{@$field->getPrefixedId()}" value="1"{if $field->isRequired()} required{/if}{if $field->isImmutable()} disabled{/if}{if $field->getValue()} checked{/if}>
+                       {@$field->getLabel()}{if $field->isRequired()} <span class="formFieldRequired">*</span>{/if}
+               </label>
+               
+               {include file='__formFieldDescription'}
+               {include file='__formFieldErrors'}
+               {include file='__formFieldDependencies'}
+               {include file='__formFieldDataHandler'}
+       </dd>
+</dl>
index e0f92d261808045b69b3e8a96a967531244d8d1a..c490d47c3f6a0fdbdeacf888bce6ad728bae1770 100644 (file)
@@ -6,6 +6,7 @@
   "templates": [
     "__aclFormField",
     "__booleanFormField",
+    "__checkboxFormField",
     "__contentLanguageFormField",
     "__dateFormField",
     "__emailFormField",
diff --git a/wcfsetup/install/files/acp/templates/__checkboxFormField.tpl b/wcfsetup/install/files/acp/templates/__checkboxFormField.tpl
new file mode 100644 (file)
index 0000000..af2e22d
--- /dev/null
@@ -0,0 +1,14 @@
+<dl id="{@$field->getPrefixedId()}Container" {if !$field->getClasses()|empty} class="{implode from=$field->getClasses() item='class' glue=' '}{$class}{/implode}"{/if}{foreach from=$field->getAttributes() key='attributeName' item='attributeValue'} {$attributeName}="{$attributeValue}"{/foreach}{if !$field->checkDependencies()} style="display: none;"{/if}>
+       <dt></dt>
+       <dd>
+               <label>
+                       <input type="checkbox" id="{@$field->getPrefixedId()}" name="{@$field->getPrefixedId()}" value="1"{if $field->isRequired()} required{/if}{if $field->isImmutable()} disabled{/if}{if $field->getValue()} checked{/if}>
+                       {@$field->getLabel()}{if $field->isRequired()} <span class="formFieldRequired">*</span>{/if}
+               </label>
+               
+               {include file='__formFieldDescription'}
+               {include file='__formFieldErrors'}
+               {include file='__formFieldDependencies'}
+               {include file='__formFieldDataHandler'}
+       </dd>
+</dl>
diff --git a/wcfsetup/install/files/lib/system/form/builder/field/CheckboxFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/CheckboxFormField.class.php
new file mode 100644 (file)
index 0000000..7df2a5b
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+namespace wcf\system\form\builder\field;
+use wcf\system\WCF;
+
+/**
+ * Implementation of a checkbox form field for boolen values.
+ * 
+ * @author     Peter Lohse
+ * @copyright  2001-2020 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Form\Builder\Field
+ * @since      5.3
+ */
+class CheckboxFormField extends BooleanFormField {
+       /**
+        * @inheritDoc
+        */
+       protected $templateName = '__checkboxFormField';
+       
+       /**
+        * @inheritDoc
+        */
+       public function getHtml() {
+               return WCF::getTPL()->fetch(
+                       $this->templateName,
+                       'wcf',
+                       [
+                               'field' => $this,
+                       ]
+               );
+       }
+}