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

Shorter links for ModelAdmin items #1075

Open
sminnee opened this issue Jul 9, 2020 · 4 comments
Open

Shorter links for ModelAdmin items #1075

sminnee opened this issue Jul 9, 2020 · 4 comments

Comments

@sminnee
Copy link
Member

sminnee commented Jul 9, 2020

Right now an item on a ModelAdmin has the URL of:
/admin/(modeladmin)/(tab)/EditForm/field/(tab)/item/214/edit

This would be usefully contracted to without losing ambiguity:
/admin/(modeladmin)/(tab)/edit/214

  • $Tab/edit/$ID Can be a new rule.
  • The default action (edit) can be supplied by the rule (since edit precedes the ID)

Changing the URLs in this way could be disruptive and so I would introduce it as an optionally enabled feature of ModelAdmin in 4.x.

To implement this, will require:

  • A new routing rule on ModelAdmin
  • A mechanism for monkeypatching the GridField item request URL generation. Probably a setter method on the GridFieldConfig component that lets the Base URL be overridden.
@sminnee
Copy link
Member Author

sminnee commented Jul 9, 2020

@chillu make sense to you?

@chillu
Copy link
Member

chillu commented Jul 9, 2020

Yeah that makes a lot of sense. Context for others, this builds on a pending PR in #1072.

I wonder if it's better to hide the complexity away from GridField and handle this within ModelAdmin only. Maybe we can make GridFieldDetailForm->handleItem() a bit smarter, and tell those particular gridfields to behave differently. Or maybe that's what you mean by "monkeypatching".

My only concern is that we're breaking URL symmetry with CMSMain here: admin/pages/edit/show/4. It's admittedly always been confusing to have edit (referring to the "edit controller") followed by show (referring to the action within that controller). How about /admin/(modeladmin)/(tab)/edit/214? That would also leave the door open to a separate view/ route later. View vs. edit isn't only decided on whether you have permissions, it's sometimes just better to look through the readonly view (e.g. with formatted markdown, without a clunky HTML editor component).

@sminnee
Copy link
Member Author

sminnee commented Jul 9, 2020

How about /admin/(modeladmin)/(tab)/edit/214?

Sounds fine. If someone adds extra actions to the GridField without also modifying ModelAdmin you would end up with something like /admin/(modeladmin)/(tab)/edit/214/view, which is a bit weird but relatively benign, and can be solved with further ModelAdmin improvements. It might make sense to customise both the view & edit URLs in the initial implementation just to validate that it's possible.

I wonder if it's better to hide the complexity away from GridField and handle this within ModelAdmin only.

Something like this makes sense to me

$gf->getConfig()->getComponentByType(GridFieldDetailForms::class)
->setItemLinkCallback(function ($gridFieldItemHandler, $record, $action) use ($modelAdmin) {
  return Controller::join_links($modelAdmin->Link(), $modelAdmin->tabName, 'edit', $record->ID);
})

So we just need to define GridFieldDetailForms::setItemLinkCallback().

With this in place, one might make even more streamlined URLs on a project-specific basis. For example, I might make riskregister.silverstripe.com/risk/14. I'd write my own project-specific call to GridFieldDetailForms::setItemLinkCallback().

@GuySartorelli
Copy link
Member

I don't think this would be valuable anymore - the changes made as part of #1354 trivialise getting a canonical edit URL for any given record, and since this isn't the front-end the value of having short URLs people can remember is basically nil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants