-
Notifications
You must be signed in to change notification settings - Fork 111
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
base: 5.0
Are you sure you want to change the base?
Conversation
@@ -209,7 +209,8 @@ public function getLink() | |||
} | |||
|
|||
// Get link from localised record | |||
return $record->Link(); | |||
$action = Controller::curr()->getRequest()->params()['Action'] ?? null; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
Fixes #458