Add `RowFormFieldContainer`
authorMatthias Schmidt <gravatronics@live.com>
Sat, 5 Oct 2019 14:48:58 +0000 (16:48 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 5 Oct 2019 14:48:58 +0000 (16:48 +0200)
Close #3086

com.woltlab.wcf/templates/__rowFormFieldContainer.tpl [new file with mode: 0644]
wcfsetup/install/files/acp/templates/__rowFormFieldContainer.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/system/form/builder/container/RowFormFieldContainer.class.php [new file with mode: 0644]

diff --git a/com.woltlab.wcf/templates/__rowFormFieldContainer.tpl b/com.woltlab.wcf/templates/__rowFormFieldContainer.tpl
new file mode 100644 (file)
index 0000000..cb55826
--- /dev/null
@@ -0,0 +1,33 @@
+<dl id="{@$container->getPrefixedId()}Container"{*
+       *}{if !$container->getClasses()|empty} class="{implode from=$container->getClasses() item='class' glue=' '}{$class}{/implode}" {/if}{*
+       *}{foreach from=$container->getAttributes() key='attributeName' item='attributeValue'} {$attributeName}="{$attributeValue}"{/foreach}{*
+       *}{if !$container->checkDependencies()} style="display: none;"{/if}{*
+*}>
+       <dt>{if $container->getLabel() !== null}<label for="{@$container->getPrefixedId()}">{@$container->getLabel()}</label>{/if}</dt>
+       <dd>
+               <div class="row rowColGap formGrid">
+                       {foreach from=$container item='field'}
+                               {if $field->isAvailable()}
+                                       <div 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}>
+                                               {@$field->getFieldHtml()}
+                                               
+                                               {include file='__formFieldErrors'}
+                                               {include file='__formFieldDependencies'}
+                                               {include file='__formFieldDataHandler'}
+                                       </div>
+                               {/if}
+                       {/foreach}
+               </div>
+               {if $container->getDescription() !== null}
+                       <small>{@$container->getDescription()}</small>
+               {/if}
+       </dd>
+</dl>
+
+{include file='__formContainerDependencies'}
+
+<script data-relocate="true">
+       require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default'], function(DefaultContainerDependency) {
+               new DefaultContainerDependency('{@$container->getPrefixedId()}Container');
+       });
+</script>
diff --git a/wcfsetup/install/files/acp/templates/__rowFormFieldContainer.tpl b/wcfsetup/install/files/acp/templates/__rowFormFieldContainer.tpl
new file mode 100644 (file)
index 0000000..cb55826
--- /dev/null
@@ -0,0 +1,33 @@
+<dl id="{@$container->getPrefixedId()}Container"{*
+       *}{if !$container->getClasses()|empty} class="{implode from=$container->getClasses() item='class' glue=' '}{$class}{/implode}" {/if}{*
+       *}{foreach from=$container->getAttributes() key='attributeName' item='attributeValue'} {$attributeName}="{$attributeValue}"{/foreach}{*
+       *}{if !$container->checkDependencies()} style="display: none;"{/if}{*
+*}>
+       <dt>{if $container->getLabel() !== null}<label for="{@$container->getPrefixedId()}">{@$container->getLabel()}</label>{/if}</dt>
+       <dd>
+               <div class="row rowColGap formGrid">
+                       {foreach from=$container item='field'}
+                               {if $field->isAvailable()}
+                                       <div 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}>
+                                               {@$field->getFieldHtml()}
+                                               
+                                               {include file='__formFieldErrors'}
+                                               {include file='__formFieldDependencies'}
+                                               {include file='__formFieldDataHandler'}
+                                       </div>
+                               {/if}
+                       {/foreach}
+               </div>
+               {if $container->getDescription() !== null}
+                       <small>{@$container->getDescription()}</small>
+               {/if}
+       </dd>
+</dl>
+
+{include file='__formContainerDependencies'}
+
+<script data-relocate="true">
+       require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/Default'], function(DefaultContainerDependency) {
+               new DefaultContainerDependency('{@$container->getPrefixedId()}Container');
+       });
+</script>
diff --git a/wcfsetup/install/files/lib/system/form/builder/container/RowFormFieldContainer.class.php b/wcfsetup/install/files/lib/system/form/builder/container/RowFormFieldContainer.class.php
new file mode 100644 (file)
index 0000000..e5463fe
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+namespace wcf\system\form\builder\container;
+use wcf\system\form\builder\field\IFormField;
+use wcf\system\form\builder\IFormChildNode;
+
+/**
+ * Represents a form container whose children which are displayed in rows and which may only be form
+ * fields.
+ * 
+ * In contrast to `RowFormContainer`, the labels and descriptions of the form fields in this container
+ * are not shown, instead there the container's label and description applies to all form fields.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Form\Builder\Container
+ * @since      5.2
+ */
+class RowFormFieldContainer extends FormContainer {
+       /**
+        * @inheritDoc
+        */
+       protected $templateName = '__rowFormFieldContainer';
+       
+       /**
+        * @inheritDoc
+        */
+       public function __construct() {
+               // does nothing
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function appendChild(IFormChildNode $child) {
+               if ((!$child instanceof IFormField)) {
+                       throw new \InvalidArgumentException("'" . static::class . "' only supports '" . IFormField::class . "' instances as children.");
+               }
+               
+               return parent::appendChild($child);
+       }
+}