Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>YoH's answer is a nice solution to this problem. </p> <p>However when I implement my status codes I like to have the message and status codes right inside my entity class.</p> <p>Therefor I wan't to show my solution which is not as good as YoH's solution because it lacks internationalization but works good for me.</p> <pre><code>class Message { ... const STATUS_NEW = 0; const STATUS_SENT = 1; const STATUS_DELIVERED = 2; ... public static $statusCodes = array( Message::STATUS_NEW =&gt; "New", Message::STATUS_SENT =&gt; "Sent", Message::STATUS_DELIVERED =&gt; "Delivered" ); public static function getStatusCodes() { return self::$statusCodes; } public function getReadableStatus() { if (!is_null($this-&gt;getStatus())) { return self::$statusCodes[$this-&gt;getStatus()]; } else { return null; } } } </code></pre> <p>And in the Sonata Admin Class for Message change the field in configureFormFields() to:</p> <pre><code>-&gt;add('status', 'choice', array( 'label' =&gt; "current Status", 'help' =&gt; "What's that status of the message ?", 'choices' =&gt; Message::getStatusCodes() ) ) </code></pre> <p>And if you want to show the value in the list then change configureListFields() to:</p> <pre><code>-&gt;add('status', 'string', array('template' =&gt; 'YourBundleName:Admin:message_list_status_field.html.twig')) </code></pre> <p>And create a twig named 'message_list_status_field.html.twig':</p> <pre><code>{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %} {% block field %} &lt;div&gt; {{ object.readableStatus }} &lt;/div&gt; {% endblock %} </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload