--- /dev/null
+{include file='__formFieldHeader'}
+
+{foreach from=$field->getOptions() key=$__fieldValue item=__fieldLabel}
+ <label><input type="radio" name="{@$field->getPrefixedId()}" value="{$__fieldValue}"{if $field->getValue() === $__fieldValue} checked{/if}> {@$__fieldLabel}</label>
+{/foreach}
+
+{include file='__formFieldFooter'}
--- /dev/null
+<?php
+namespace wcf\system\form\builder\field;
+
+/**
+ * Implementation of a radio buttons form field for selecting a single value.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2018 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Form\Builder\Field
+ * @since 3.2
+ */
+class RadioButtonFormField extends AbstractFormField implements ISelectionFormField {
+ use TSelectionFormField;
+
+ /**
+ * @inheritDoc
+ */
+ protected $templateName = '__radioButtonFormField';
+
+ /**
+ * @inheritDoc
+ */
+ protected static function supportsNestedOptions(): bool {
+ return false;
+ }
+}
$validateOptions = function(array &$array) use (&$validateOptions) {
foreach ($array as $key => $value) {
if (is_array($value)) {
- $validateOptions($value);
+ if (static::supportsNestedOptions()) {
+ $validateOptions($value);
+ }
+ else {
+ throw new \InvalidArgumentException("Option '{$key}' must not be an array.");
+ }
}
else {
if (!is_string($value) && !is_numeric($value)) {
return parent::value($value);
}
+
+ /**
+ * Returns `true` if the field class supports nested options and `false` otherwise.
+ *
+ * @return bool
+ */
+ protected static function supportsNestedOptions(): bool {
+ return true;
+ }
}