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

Allow mutators for Settings models and improve API #1080

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

bennothommo
Copy link
Member

@bennothommo bennothommo commented Mar 5, 2024

Fixes #1047. Replaces #1071.

  • Use getAttribute method in the model.setAttribute listener within the SettingsModel behavior to retrieve the (possibly) mutated value before saving into settings array.
  • Ensure that default values populated by initSettingsData method in a Settings model are populated into settings array if not yet persisted in the DB, so that they are accessible via model properties.
  • Allow values to be retrieved as model properties at any time.

- Use "getAttribute" method to retrieve possibly mutated value before saving into settings array.
- Ensure that default values populated by "initSettingsData" are populated into settings array if not yet persisted in the DB
- Allow values to be retrieved as model properties at any time.
@bennothommo bennothommo added maintenance PRs that fix bugs, are translation changes or make only minor changes needs review Issues/PRs that require a review from a maintainer labels Mar 5, 2024
@bennothommo bennothommo added this to the 1.2.5 milestone Mar 5, 2024
@bennothommo bennothommo mentioned this pull request Mar 5, 2024
@bennothommo
Copy link
Member Author

@goldmont would you be willing to test this PR as an alternate fix for #1047? I've added a test case for your scenario, but happy to hear if it works out in the wild.

@@ -174,12 +176,14 @@ public function getSettingsValue($key, $default = null)
/**
* Set a single setting value, if allowed.
*/
public function setSettingsValue($key, $value)
public function setSettingsValue($key)
Copy link
Member

Choose a reason for hiding this comment

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

This change confused for me for a bit before I realized that is method is somewhat performing double duty. The first use-case is the public api of setSettingsValue($key, $value), but the second use-case (the one addressed by this PR and the other PRs) is to sync the model data to the internal fieldValues array whenever setAttributes() is called.

@bennothommo what do you think about changing it so that the model.setAttribute event listener is instead a protected method syncModelAttribute($key) that then does $this->setSettingsValue($key, $this->model->getAttribute($key)) and leave this method unmodified?

Copy link
Member Author

@bennothommo bennothommo Mar 6, 2024

Choose a reason for hiding this comment

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

@LukeTowers I think we should come to a conclusion on what we're going to be doing about the actual event. If we either fix up the event or add the third parameter, then I'll have to change this anyway - fixing up the event would mean we don't need this PR at all (beyond maybe the additional afterModelFetch calls to ensure everything works as properties).

Copy link
Member

Choose a reason for hiding this comment

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

@bennothommo perhaps we can get on a call about this, I'm still not really understanding the problem with the event itself, would probably be easier to talk it through when you have a minute 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi,

Let me know what and when to test. Thanks for your efforts.

Copy link
Member

Choose a reason for hiding this comment

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

@goldmont is this still an issue for you?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi,

I "solved" by using the Encryption trait.

@LukeTowers LukeTowers modified the milestones: 1.2.5, 1.2.6 Mar 12, 2024
@LukeTowers LukeTowers modified the milestones: 1.2.6, 1.2.7 Apr 25, 2024
@LukeTowers LukeTowers modified the milestones: 1.2.7, 1.2.8 Jul 22, 2024
@bennothommo bennothommo removed the needs review Issues/PRs that require a review from a maintainer label Oct 11, 2024
@bennothommo bennothommo marked this pull request as draft October 11, 2024 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance PRs that fix bugs, are translation changes or make only minor changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Model mutators not working using SettingsModel behavior
3 participants