Fix: Form validation on optional, empty fields of types 'Element\Url' and 'OmekaElement\PropertySelect'#48
Conversation
Details: Add `required => false, allow_empty => true` for every `AbstractVocabularyMemberSelect` instance (the common ancestor of `PropertySelect`).
|
Added an additional commit that also fixes the silent save failure on fields of type
This is why fixing only the Fix |
Note
This fix solves the issue described at Daniel-KM/Omeka-S-module-ImageServer#9
I have used Copilot & Claude to investigate the issue and come with a fix. I have reviewed the code that was changed in the modules ImageServer and IiifServer and have tested it functionally in my Omeka S setup. I am satisfied with the result and hereby contribute the changed code to the upstream source code.
For module ImageServer I will create separate PR in which I will refer to both the issue and this PR.
Problem
Submitting the module configuration form would silently fail to save any settings. The page would reload showing the previous unmodified values with no error message indicating what went wrong.
Root cause
Both the ImageServer and IiifServer config forms used Laminas's
Element\Urlfor optional URL fields. Laminas'sElement\Urlapplies aUrivalidator that rejects empty strings by default. When these optional fields were left blank (which is the initial state after the modules get installed),$form->isValid()returnedfalse, causinghandleConfigFormAuto()to returnfalse— which prevents any settings from being saved.Because the Omeka core
ModuleControlleronly redirects on a truthy return value, the page simply re-rendered with the original settings and no visible error.This regression was introduced when explicit
required => falseinput filter specifications were removed from the forms.Fix
Added input filter specifications for all optional
Element\Urlfields to explicitly setrequired => falseandallow_empty => true. This tells Laminas to skip URL validation when the field is empty, while still validating the URL format when a value is provided.ImageServer (src/Form/ConfigForm.php):
IiifServer (src/Form/ConfigForm.php):