Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Modifying SummaryFields as they are displayed

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

Page: 1 2
Go to End
Author Topic: 3320 Views
  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: Modifying SummaryFields as they are displayed Link to this post

    Nice one martimiz! This will definitely come in handy.

    I was in fact referring to ModelAdmin in this instance. Any pointers?

  • martimiz
    Avatar
    Forum Moderator
    1035 Posts

    Re: Modifying SummaryFields as they are displayed Link to this post

    Yeah, well.. In ModelAdmin, FieldFormatting for the tlf is set in the getResultsTable(..) method in the ModelAdmin_CollectionController class, where it creates the clickable link around the field value. So this would be a very dirty hack (just to hint):

    ModelAdmin.php line 721 - replace:

    function getResultsTable($searchCriteria) {
    ...
    $tf->setFieldFormatting(array_combine(array_keys($summaryFields), array_fill(0,count($summaryFields), $url)));
    ...
    }

    By:

    function getResultsTable($searchCriteria) {
    ...
    $arrFormatting = array_combine(array_keys($summaryFields), array_fill(0,count($summaryFields), $url));

    $arrFormatting['Date'] = str_replace('$value', '$NiceDate', $arrFormatting['Date']);

    $tlf->setFieldFormatting($arrFormatting);
    ...
    }

    Doing it the proper way would require some major extending of the ModelAdmin classes, I guess, and defining some sort of $formatted_fields static property, equivalent to $summary fields, unless I'm missing something obvious. It is doable, but would be a nice new feature for the ModelAdmin class maybe

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: Modifying SummaryFields as they are displayed Link to this post

    Ok, thank you very much for that Martimiz.

    As much as I dislike dirty hacks, if this is what the client wants it's what they get!

    I agree it would be a good feature for ModelAdmin.

    3320 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.