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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Model/RecordLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...

return $record->Link($action);
}

/**
Expand Down