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

Include action in locale links #688

Open
wants to merge 1 commit into
base: 5.0
Choose a base branch
from

Conversation

purplespider
Copy link

Fixes #458

@@ -209,7 +209,8 @@ public function getLink()
}

// Get link from localised record
return $record->Link();
$action = Controller::curr()->getRequest()->params()['Action'] ?? null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The problem here is that you are making a model action dependant on controller state, which creates a risky and inverse dependency between model / controller.

Better solution: Allow getLink to take an action (like nearly every other link / relative link method) and conditionally join it.

E.g.

public function getLink($action = null) {
}

and remove Controller::curr() in it's entirety. :)

Then you can use $Link('show') in your custom template.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You could also support this with $record->LocaleLink($this->getLocale(), $action)

Copy link
Collaborator

Choose a reason for hiding this comment

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

The main reason I have a problem with this code is that Controller::curr() may not necessarily be the controller for the record in question. E.g. Controller::curr() being Security, but $record being a HomePage class.

It's risky to make this presumption.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Better solution:

  • add $action to getLink() method
  • add getCurrentLink() method, that assumes the current controller action, and calls getLink() with the current action / id / etc...

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.

Action is NOT appended to the page Locale URL
2 participants