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: allow resetting settings to default #3935

Merged
merged 8 commits into from
Oct 21, 2024

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!

SychO9 and others added 3 commits October 21, 2024 12:06
…lues

# Conflicts:
#	framework/core/src/Extend/Settings.php
#	framework/core/tests/integration/extenders/SettingsTest.php
@SychO9 SychO9 added this to the 2.0 milestone Oct 21, 2024
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.

Thanks! Sorry for the delay.

Documentation added: flarum/docs#478

@SychO9 SychO9 changed the title feat: add forget method to settings extender feat: allow resetting settings to default Oct 21, 2024
@SychO9 SychO9 merged commit 084ae6f into 2.x Oct 21, 2024
25 checks passed
@SychO9 SychO9 deleted the tk/3934-empty-settings-dont-return-default-values branch October 21, 2024 14:17
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.

Empty settings don't return default values
3 participants