fix(container.class): Prevent item creation with null value for mandatory fields#1229
Merged
Conversation
Rom1-B
requested changes
Jul 22, 2026
Comment on lines
+1973
to
+1980
| if ($item->isNewItem() && $loc_c->fields['type'] === 'dom') { | ||
| $data = ['plugin_fields_containers_id' => $c_id]; | ||
| if (self::validateValues($data, $item::getType(), isset($_REQUEST['massiveaction'])) === false) { | ||
| $item->input = []; | ||
|
|
||
| return false; | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
The minimal $data array built for this new validation path omits the status field. populateData()'s normal path always sets $data[$status_field_name] from $item->input/$item->fields (lines 2029-2034), and validateValues() resolves $status_value = $data[$status_field_name] ?? null to apply PluginFieldsStatusOverride mandatory/readonly relaxations (line 1673). Since this new branch never sets that key, any status override waiving a field's mandatory flag for a given creation status is silently ignored here, so a legitimate creation (API/CLI, dom container, status override in place) gets incorrectly blocked.
Suggested change
| if ($item->isNewItem() && $loc_c->fields['type'] === 'dom') { | |
| $data = ['plugin_fields_containers_id' => $c_id]; | |
| if (self::validateValues($data, $item::getType(), isset($_REQUEST['massiveaction'])) === false) { | |
| $item->input = []; | |
| return false; | |
| } | |
| } | |
| if ($item->isNewItem() && $loc_c->fields['type'] === 'dom') { | |
| $status_field_name = PluginFieldsStatusOverride::getStatusFieldName($item::getType()); | |
| $data = ['plugin_fields_containers_id' => $c_id]; | |
| if (array_key_exists($status_field_name, $item->input) && $item->input[$status_field_name] !== '') { | |
| $data[$status_field_name] = (int) $item->input[$status_field_name]; | |
| } elseif (array_key_exists($status_field_name, $item->fields) && $item->fields[$status_field_name] !== '') { | |
| $data[$status_field_name] = (int) $item->fields[$status_field_name]; | |
| } | |
| if (self::validateValues($data, $item::getType(), isset($_REQUEST['massiveaction'])) === false) { | |
| $item->input = []; | |
| return false; | |
| } | |
| } |
Rom1-B
approved these changes
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist before requesting a review
Please delete options that are not relevant.
Description
preItem(), the validation of required fields (validateValues()) was only called ifpopulateData()did not returnfalse. However,populateData()returnsfalsewhen none of the block's fields are present in the input. Result: A creation that did not submit the fields (API/CLI, or a form without mapping) completely bypassed the check and created the element with aNULLvalue in a required field.isNewItem()), whenpopulateData()returnsfalseand the continer type isdom,validateValues()is still called on an empty dataset, which causes the missing required fields to fail validation and blocks creation.