Requiring a minimum age for registrations now marks the fields as required
authorAlexander Ebert <ebert@woltlab.com>
Wed, 26 Jan 2022 18:31:09 +0000 (19:31 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 26 Jan 2022 18:31:09 +0000 (19:31 +0100)
See https://www.woltlab.com/community/thread/291431-mindestalter-geburtsdatum-ist-pflichtfeld-wird-aber-nicht-so-deklariert/

wcfsetup/install/files/lib/data/user/option/UserOption.class.php
wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php

index 09e111c44dfcb2fd21db87ea883fd048da5968fd..6e84976fcd639022aa79ed21d78dc2293aacaa01 100644 (file)
@@ -229,4 +229,9 @@ class UserOption extends Option implements ITitledObject
     {
         $this->data['visible'] = $visibleOption;
     }
+
+    public function setRequired(bool $isRequired): void
+    {
+        $this->data['required'] = $isRequired ? 1 : 0;
+    }
 }
index 16782ae0e17e5bce7c5cd793c45b7774beff737d..b6e91a5ee0966001148f91a9fe2a7bd3e5488de5 100644 (file)
@@ -71,6 +71,19 @@ class UserOptionHandler extends OptionHandler
      */
     public $conditionMode = false;
 
+    public function init()
+    {
+        parent::init();
+
+        if ($this->inRegistration && REGISTER_MIN_USER_AGE) {
+            foreach ($this->options as $option) {
+                if ($option->optionName === 'birthday') {
+                    $option->setRequired(true);
+                }
+            }
+        }
+    }
+
     /**
      * Shows empty options.
      *