ozahorulia
ozahorulia

Reputation: 10084

SonataAdmin: replace ID in breadcrumbs

How can I replace Object's ID in SonataAdmin breadcrumbs by some other text?

If I set __toString() in my document, it works only for editing. When I attempt to create new record, there is something like MyDocument:0000000000e09f5c000000006a48ef49 in the last breadcumb.

I'm searching for a method which allows me to set some text as the last breadcump if Document::toString() returns null.

Upvotes: 7

Views: 3538

Answers (2)

Thomas Decaux
Thomas Decaux

Reputation: 22681

BTW something cool to know, you can completely customize the breadcrumb via a Twig template:

{% block sonata_breadcrumb %}

    {% set _breadcrumb %}
        <li><a href="#">Home</a></li>
        <li><a href="#">Library</a></li>
        <li class="active">Data</li>
    {% endset %}

    {{ parent() }}

{% endblock %}

Upvotes: 1

TautrimasPajarskas
TautrimasPajarskas

Reputation: 2796

This behaviour is implemented directly in the entity:

public function __toString()
{
    return $this->getFoo() ? : '-';
}

Bundles are using variants of this, including return (string)$this->getFoo(); or $this->getFoo() ? : 'n/a'; etc.

Related question: toString method for SonataAdminBundle Listing in Symfony2

Upvotes: 14

Related Questions