Skip to content

Conversation

@purplespider
Copy link

Fixes #458


// 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