datlechin
I edited the AddBirthdayValidation.php file and it works fine with the "required" registration part.
public function __invoke(UserValidator $flarumValidator, Validator $validator): void
{
$rules = $validator->getRules();
$isRequired = $this->settings->get('datlechin-birthdays.required')
&& $this->settings->get('datlechin-birthdays.set_on_registration');
$rules['birthday'] = [
'nullable',
Rule::requiredIf($isRequired && ! $flarumValidator->getUser()),
$set_isRequired,
'date_format:Y-m-d',
'before:today',
function ($attribute, $value, $fail) {
if ($value) {
$birthday = new DateTime($value);
$now = new DateTime();
$diff = $now->diff($birthday);
if ($diff->y <= (int) $this->settings->get('datlechin-birthdays.min_age')) {
$fail($this->translator->trans('datlechin-birthdays.api.invalid_age_message', [
'minAge' => (int) $this->settings->get('datlechin-birthdays.min_age')
]));
} else if ($diff->y > 100) {
$fail($this->translator->trans('datlechin-birthdays.api.invalid_dob_message'));
}
}
},
];
$validator->setRules($rules);
}
FIX:
public function __invoke(UserValidator $flarumValidator, Validator $validator): void
{
$rules = $validator->getRules();
$isRequired = $this->settings->get('datlechin-birthdays.required')
&& $this->settings->get('datlechin-birthdays.set_on_registration');
if ($isRequired && ! $flarumValidator->getUser()) {
$set_isRequired = 'required';
} else {
$set_isRequired = 'nullable';
}
$rules['birthday'] = [
//'nullable',
//Rule::requiredIf($isRequired && ! $flarumValidator->getUser()),
$set_isRequired,
'date_format:Y-m-d',
'before:today',
function ($attribute, $value, $fail) {
if ($value) {
$birthday = new DateTime($value);
$now = new DateTime();
$diff = $now->diff($birthday);
if ($diff->y <= (int) $this->settings->get('datlechin-birthdays.min_age')) {
$fail($this->translator->trans('datlechin-birthdays.api.invalid_age_message', [
'minAge' => (int) $this->settings->get('datlechin-birthdays.min_age')
]));
} else if ($diff->y > 100) {
$fail($this->translator->trans('datlechin-birthdays.api.invalid_dob_message'));
}
}
},
];
$validator->setRules($rules);
}
DEMO TEST: https://flarum.khatvongsong.vn/
DISABLE: Required entering birthdays
ENALBLE: Required entering birthdays