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

FIX: Source locale indicator correction. #840

Open
wants to merge 2 commits into
base: 7
Choose a base branch
from

Conversation

mfendeksilverstripe
Copy link
Contributor

@mfendeksilverstripe mfendeksilverstripe commented Apr 5, 2024

FIX: Source locale indicator correction.

Description

Source locale detection corrected to take into account locale inheritance settings for a specific model. Impacted methods are only used in the CMS UI to give indication to content authors on what to expect (what is the source locale of the content). Before this change the indicator could be inaccurate in a sense that it would indicate content and there would actually not be any content to display.

319797975-24c993d8-8ac2-4704-8a61-694797fa6d64

This change should have no impact on actual content rendering.

Change-set breakdown

  • RecordLocale::getSourceLocale() now takes into account locale inheritance mode
  • FluentExtension::getSourceLocale() is now only a shorthand method to the above method instead of maintaining its own implementation that doesn't cover all the cases

Manual testing steps

  • assumes CMS 5 installer + Fluent
  • navigate to the CMS under locales admin
  • create first locale - English (Any english) and set this locale to be the global default
  • create second locale - German and set the this locale to fall back to the first locale
  • create a campaign page (code snippet below)
class CampaignPage extends Page
{
    private static string $frontend_publish_required = FluentExtension::INHERITANCE_MODE_EXACT;
}
  • run dev/build with flush
  • reload the CMS admin pages and navigate to the pages section
  • make sure you are in the English locale (see locale selector in the top left)
  • create a campaign page (fill any data in)
  • navigate to the localisation manager tab within the campaign page edit form
  • you should see two records displayed (one for each locale)
  • check the source locale for the German locale for this campaign page
  • the expected value is "No source" (state after the change), before this change-set it would show English locale

Most common scenarios:

  • Page uses fallback inheritance mode (default)
  • Assets use any inheritance mode
  • Campaign pages use exact inheritance mode

The source locale indicator should be in line with what is shown on the frontend.

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

@mfendeksilverstripe
Copy link
Contributor Author

This is ready for a review @GuySartorelli

Copy link
Contributor

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

I haven't checked anything beyond what I've requested changes for below, since these changes will require either retargetting the PR or fundamentally changing the approach.

src/Extension/FluentExtension.php Outdated Show resolved Hide resolved
*
* @return Locale|null
*/
public function getSourceLocale()
public function getSourceLocale(?bool $isFrontend = true): ?Locale
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public function getSourceLocale(?bool $isFrontend = true): ?Locale
public function getSourceLocale()

Additional parameters (even optional ones) and explicit typehints cannot be added outside of a major release.
See the definition of public API

Copy link
Contributor

Choose a reason for hiding this comment

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

If those changes are required, they will need to target 8 so they can be included in the next major release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll see if I can find another way 🤔

src/Model/RecordLocale.php Outdated Show resolved Hide resolved
@GuySartorelli
Copy link
Contributor

Please also avoid @ing me on each PR unless it is something you crucially need to be checked in the immediate future.

@mfendeksilverstripe
Copy link
Contributor Author

New changes added: updated API so they match minor constraints, so this can be based on 7 branch.

Copy link
Contributor

@GuySartorelli GuySartorelli 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 reviewed properly yet. I'll add this to my list of things to try get to this week unless someone else gets to it before me

src/Extension/FluentExtension.php Outdated Show resolved Hide resolved
// This model requires localisation so fallback of any kind is not allowed
// hence the content can't come from another locale
// We don't have a source locale for such case
if ($inheritanceMode === FluentExtension::INHERITANCE_MODE_EXACT) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good! I was trying to remind myself how inheritance worked, but this line seems to obviously fix the issue. We should never care about fallbacks if inheritance is exact mode only.

@GuySartorelli
Copy link
Contributor

Can you please update the PR description to give actual step-by-step instructions for how to reproduce this from a fresh installation? Include any code samples for setting configuration, and exact steps required - assume I don't know anything about fluent :p

As it stands I'm not really sure what the behaviour was before this PR, what it should be afterward, and how to confirm either of those.

@mfendeksilverstripe
Copy link
Contributor Author

I've added test setup details into the description of this PR as requested @GuySartorelli

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.

3 participants