Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Modify how ModelAdmin shows DataObject titles


Go to End


3 Posts   1465 Views

Avatar
Jare

Community Member, 39 Posts

14 February 2016 at 5:36am

Hi,

I have a class named Document which extends DataObject and a class named DocumentAdmin which extends ModelAdmin. When editing a Document through the ModelAdmin view, I would like to modify how the ModelAdmin displays the title text of the Document in the very top of the page. The reason for this is that the Documents have usually very long titles which will take up a lot of space as they go to a second row. If you need, I can post a screenshot to demonstrate the problem.

Avatar
Devlin

Community Member, 344 Posts

19 February 2016 at 12:10am

There multiple ways to do that.

The simplest way would be to copy the template "framwork/admin/templates/CMSBreadcrumbs.ss" to "mysite/templates/CMSBreadcrumbs.ss" and change its content to limit the characters of your title.

...
<% if $Last %>
	<span class="cms-panel-link crumb last">$Title.LimitCharacters(50).XML</span>
<% else %>
...

Though, this will change all the breadcrumbs where it is used, but I guest that this is not that bad.

The correct way would be to:
- override GridFieldDetailForm->Breadcrumbs() to trim the Title: "'Title' => substr($this->record->Title, 0, 50)"
and
- override ModelAdmin->getEditForm() to remove the original GridFieldDetailForm component and add your new GridFieldDetailForm component

Avatar
Jare

Community Member, 39 Posts

19 February 2016 at 3:20am

Thank you, Devlin! :)