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

Permissions overwritten if the same field is re-used in different layouts #20

Open
goraxan opened this issue Jul 2, 2020 · 2 comments
Assignees

Comments

@goraxan
Copy link

goraxan commented Jul 2, 2020

Due to how the Craft fields service handles layout updates (they delete the layout and re-create it every time https://github.com/craftcms/cms/blob/master/src/services/Fields.php#L1248) the permissions attached to one field get deleted every time a layout is saved because the ON CASCADE FK on fieldId references the fieldlayoutfields table.
When the Fab service saves the permissions (in the saveFieldLayoutPermissions method) it only saves the permissions of the layout being modified at that moment, the rest remain deleted.

Is there any way to re-use a field across different layouts?

@goraxan goraxan changed the title Permissions overwritten if the same field is re-used in different sections Permissions overwritten if the same field is re-used in different layouts Jul 2, 2020
@goraxan
Copy link
Author

goraxan commented Jul 2, 2020

One way of solving it would be to remove the FKs to fieldlayoutfields and fieldlayouttabs, thus avoid the implicit deletion of the current permissions every time a layout is saved, and rely on EVENT_AFTER_DELETE_FIELD_LAYOUT and EVENT_AFTER_DELETE_FIELD events to explicitly delete the related permissions upon deletion.

@moacode moacode self-assigned this Jul 3, 2020
@moacode
Copy link
Owner

moacode commented Jul 3, 2020

Thanks @goraxan, I hadn't encountered this scenario—It is a bit of a pain how Craft re-creates the layout each time. What you've suggested sounds like a good solution though so I'll have a crack and keep you updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants