Skip to content
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

Merged
merged 2 commits into from
Feb 7, 2018
Merged

Introduction of protected field names #480

merged 2 commits into from
Feb 7, 2018

Conversation

jorisvaesen
Copy link
Collaborator

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

@josegonzalez
Copy link
Member

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;
Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes perfect sense.

Copy link
Member

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

Copy link
Collaborator Author

@jorisvaesen jorisvaesen Feb 6, 2018

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,
]

Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Member

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. 🙂

@josegonzalez josegonzalez merged commit 67338ef into FriendsOfCake:master Feb 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants