-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduction of protected field names #480
Conversation
Needs documentation :) |
@@ -80,6 +83,10 @@ public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $opti | |||
public function beforeSave(Event $event, Entity $entity, ArrayObject $options) | |||
{ | |||
foreach ($this->config() as $field => $settings) { | |||
if (in_array($field, $this->protectedFieldNames)) { | |||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should instead raise an exception here so that developers catch this during development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes perfect sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably write a test too, so we know the Exception happens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I took a second look at it, this would make it impossible for the user to pass the priority setting to the plugin? The setting should not be used by the plugin but should be available to Cake itself.
So it's not an error when you set a protected field, the user must be aware that it's used by Cake and not the plugin, as documented.
This should be taken as a valid config:
[
'file' => [],
'image' => [],
'priority' => 11,
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I feel as though someone - @ADmad ? @dereuromark? - complained about the top-level key being the field names. Maybe we can introduce a fields
key and deprecate the old method, skip priority, and then in a new major, remove support for top-level field configurations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the way to go. I guess this can be merged and released since it is properly documented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I did complain about the field names being top level keys in the past. Surprised it took so long for someone to eventually face a problem due to it. 🙂
This protects the system from taking a behavior setting as a file upload field. I came across this issue when using the priority flag as documented on https://api.cakephp.org/3.3/class-Cake.ORM.Behavior.html