title: How to add a "fallback label" in sonata admin list views
body: <p>I am displaying some entity relations in a Sonata Admin list view. The problem: When no relation exists (what is legal in my case) the table cell stays empty:</p>
  
  <p><a href="https://i.stack.imgur.com/BT1np.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BT1np.png" alt="enter image description here"></a></p>
  
  <p>What I want is basically this:</p>
  
  <p><a href="https://i.stack.imgur.com/Owp0w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Owp0w.png" alt="enter image description here"></a></p>
  
  <p>I tried to overwrite the default template (<code>base_list_field.html.twig</code>):</p>
  
  <pre><code>$listMapper
      -&gt;add(
          'example',
          null,
          array(
              'template' =&gt; 'AppBundle:Admin:listItemWithFallback.html.twig'
          )
      )
  ;
  </code></pre>
  
  <p>But even when I only extend the default template, all links for existing references stop working. Also I cannot figure out where to add my fallback. My <code>AppBundle:Admin:listItemWithFallback.html.twig</code> looks like this:</p>
  
  <pre><code>{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
  </code></pre>
  
  <p>With this result:</p>
  
  <p><a href="https://i.stack.imgur.com/D2yFs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D2yFs.png" alt="enter image description here"></a></p>
  
  <p>Even when I copy the whole code from <code>base_list_field.html.twig</code> into my own template, the links stop to work.</p>
  
  <p>So: How can I add a fallback label without overwriting the whole default templates? I want to modify as less of the base templates as possible.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>This is a workaround using a <code>kernel.event_listener</code>, hope there is a nicer way to achieve this:</p>
  
  <p><code>services.yml</code>:</p>
  
  <pre><code>services:
      empty_cells.listener:
          class: AppBundle\Listener\EmptyAdminTableCellListener
          arguments:
              - '@translator'
          tags:
             - { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }
  </code></pre>
  
  <p><code>EmptyAdminTableCellListener.php</code>:
      
  
  <pre><code>namespace AppBundle\Listener;
  
  use Symfony\Component\Translation\TranslatorInterface;
  use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  
  class EmptyAdminTableCellListener
  {
      /**
       * @var TranslatorInterface
       */
      protected $translator;
  
      /**
       * @param TranslatorInterface $translator
       */
      public function __construct(TranslatorInterface $translator)
      {
          $this-&gt;translator = $translator;
      }
  
      /**
       * @param FilterResponseEvent $event
       */
      public function onKernelResponse(FilterResponseEvent $event)
      {
          $request = $event-&gt;getRequest();
          $path    = $request-&gt;getPathInfo();
  
          if (strpos($path, '/admin/') !== false) {
              $emptyText = $this-&gt;translator-&gt;trans('Not set', [], 'admin');
              $response  = $event-&gt;getResponse();
              $content   = $response-&gt;getContent();
  
              $content   = preg_replace(
                  ';(&lt;td[^&gt;]*?&gt;)[\s]+?(&lt;/td&gt;);is',
                  sprintf('$1%s$2', $emptyText),
                  $content
              );
  
              $response-&gt;setContent($content);
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Nx5Sv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nx5Sv.png" alt="enter image description here"></a></p>