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

feat: add forget method to settings extender #3935

Open
wants to merge 5 commits into
base: 2.x
Choose a base branch
from

Conversation

OrdinaryJellyfish
Copy link
Contributor

@OrdinaryJellyfish OrdinaryJellyfish commented Nov 23, 2023

Fixes #3934

Changes proposed in this pull request:

  • Adds a forget method to settings extender. This method allows a callback returning a bool, which if returns true, deletes the setting so the default is used.

Reviewers should focus on:

  • Whether this new extender was written properly
  • If the forget method properly deletes a setting when callback returns true

Screenshot

QA

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

Required changes:

  • Related documentation PR: (Remove if irrelevant)
  • Related core extension PRs: (Remove if irrelevant)

@OrdinaryJellyfish OrdinaryJellyfish requested a review from a team as a code owner November 23, 2023 22:13
@OrdinaryJellyfish OrdinaryJellyfish linked an issue Nov 23, 2023 that may be closed by this pull request
Copy link
Member

@SychO9 SychO9 left a comment

Choose a reason for hiding this comment

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

Close enough but not quite ;)

The problem we are trying to solve is that, when the admin saves a value (empty string for example) that will be used as the setting value, even if an extension developer adds a setting that must be filled.

So the idea is that the callback will be used in the SetSettingsController class to determine which values to save and which to forget, because when an admin saves settings from the admin UI that's the controller that's used.

Copy link
Member

@SychO9 SychO9 left a comment

Choose a reason for hiding this comment

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

Haven't tested yet, But this looks good!

Now all we have to do (as per the conversation with Sasha on the issue) is to inverse the intent (and the name) of the forget extender. So instead of saying forget this setting when the value equals this. It would become store this setting when the value is this.

For naming, maybe filter would make sense, what do you think?

@OrdinaryJellyfish
Copy link
Contributor Author

Sounds good to me!

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

Successfully merging this pull request may close these issues.

Empty settings don't return default values
2 participants