silverstripe-admin icon indicating copy to clipboard operation
silverstripe-admin copied to clipboard

Shorter links for ModelAdmin items

Open sminnee opened this issue 5 years ago • 4 comments

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 avatar Jul 09 '20 01:07 sminnee

@chillu make sense to you?

sminnee avatar Jul 09 '20 01:07 sminnee

Yeah that makes a lot of sense. Context for others, this builds on a pending PR in https://github.com/silverstripe/silverstripe-admin/pull/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).

chillu avatar Jul 09 '20 01:07 chillu

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().

sminnee avatar Jul 09 '20 01:07 sminnee

I don't think this would be valuable anymore - the changes made as part of https://github.com/silverstripe/silverstripe-admin/issues/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.

GuySartorelli avatar May 22 '24 21:05 GuySartorelli