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

API Add $action parameter to Controller::Link #5854

Conversation

tractorcow
Copy link
Contributor

Reverts 1ccdcba

This is necessary to fix some actions in gridfield, where the form Link() action isn't being correctly concatenated to the parent controller.

Prior to this fix, clicking the gridfield header would cause a HTTP error (HTTP request was to /admin/reports/EditForm/field/Reports, instead of /admin/reports/index/EditForm/field/Reports)

The problem is that some controllers need to know if they are being appended to nested controllers, and occasionally need to add the full urlsegment in those cases. The 'home' page and the reports 'index' actions are two examples.

@tractorcow tractorcow added this to the CMS 4.0.0-alpha2 milestone Aug 1, 2016
@tractorcow tractorcow force-pushed the pulls/4.0/controller-link-standardise branch 2 times, most recently from d192511 to 3e82492 Compare August 1, 2016 01:48
@tractorcow
Copy link
Contributor Author

There seems to be a regression in GridField... looking into it now.

public function Link() {
return get_class($this) .'/';
public function Link($action = null) {
return Controller::join_links(get_class($this), $action, '/');
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Why not just call with get_class + func_get_args - $action isn't guaranteed to be an action, it'll just be whatever the caller wants
  2. Does it need to finish with a '/'? And if so, can't join_links do that, instead of added it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. We don't want all args, just the one. See tests below; I'm relying on $action being ignored if empty.
  2. Modifying join_links could have a larger range of unexpected consequences, so I've opted for the least disruptive change.

@tractorcow tractorcow force-pushed the pulls/4.0/controller-link-standardise branch from 3e82492 to f088efc Compare August 1, 2016 04:30
@tractorcow
Copy link
Contributor Author

I've removed the change in behaviour to Form::FormAction() to reduce regressions.

This change will now standardise the behaviour of Controller::link(), but will not increase reliance on this standard behaviour. There were too many regressions in GridField due to the original rewrite.

@dhensby
Copy link
Contributor

dhensby commented Aug 1, 2016

We need a CMS fix too

@tractorcow
Copy link
Contributor Author

CMS fix at silverstripe/silverstripe-cms#1570 @dhensby , thanks!

@tractorcow tractorcow force-pushed the pulls/4.0/controller-link-standardise branch from f088efc to 9188628 Compare August 1, 2016 22:36
@tractorcow tractorcow closed this Aug 2, 2016
@tractorcow tractorcow reopened this Aug 2, 2016
@tractorcow
Copy link
Contributor Author

Restarting tests.

@hafriedlander hafriedlander merged commit 18465e7 into silverstripe:master Aug 2, 2016
@tractorcow tractorcow deleted the pulls/4.0/controller-link-standardise branch August 2, 2016 04:43
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.

None yet

3 participants