title: Symfony2 & Annotations & Choices Validation: How to store and retrieve choices options?
body: <p>I have a dynamic list of choices to display in a form and I just want to maintain them in one place, as these are not the only datasets I have to care for.</p>
  
  <p>To validate those choices in the Entity over choices-CallbackValidator I would need to specify a fix class and function where the choices would be returned.</p>
  
  <p>This seems not right as I am still learning Symfony2 and the DIC concept and then I would not expect to specify a concrete callback function/class, but a service or think of another way to solve this.</p>
  
  <p>I would like to give not a classname, but a service name as callback. Am I wrong here?</p>
  
  <p>I need the list of options to </p>
  
  <ul>
  <li>fill the form</li>
  <li>to validate the entity with annotations</li>
  <li>to know where to send emails (later)</li>
  </ul>
  
  <p>Setup now:</p>
  
  <p>services.yml - The DataManager defined with service_container and the Form as a service (I don't know if this is right):</p>
  
  <pre><code>services:
    data_manager:
      class:  TestBundle\Service\DataManager
      arguments:
              - "@service_container"
              - %tc_data.list%
    support_type_form:
      class: TestBundle\Form\Type\TicketType
      arguments: ["@service_container"]
      tags:
          - { name: form.type }
  </code></pre>
  
  <p>The Form:</p>
  
  <pre><code>class TicketType extends FormType
  {
      public function buildForm(FormBuilder $builder, array $options)
      {
          $theChoices = $this-&gt;getContainer()-&gt;get('data_manager')-&gt;getTheChoices();
          ...
      }
  }
  </code></pre>
  
  <p>The Entity:</p>
  
  <pre><code>class Ticket
  {
      /**
       * @Assert\NotBlank()
       * @Assert\Choice(callback = {"NotAServiceReference", "getTheChoices"})
       */
      private $the_list_field;
  }
  </code></pre>
  
  <p>So I have the list of data in the service, but how would you suggest I retrieve the choices to validate the Entity?</p>
  
  <p>Another solution I thought of was using the Callback validation (link 2), but even there in the docs it sais:</p>
  
  <pre><code>// somehow you have an array of "fake names"
  $fakeNames = array();
  </code></pre>
  
  <p>How did/would you solve this?</p>
  
  <p>References:</p>
  
  <ol>
  <li>See: <a href="http://symfony.com/doc/current/reference/constraints/Choice.html#supplying-the-choices-with-a-callback-function" rel="nofollow">http://symfony.com/doc/current/reference/constraints/Choice.html#supplying-the-choices-with-a-callback-function</a> (click annotations)</li>
  <li>See: <a href="http://symfony.com/doc/current/reference/constraints/Callback.html#the-callback-method" rel="nofollow">http://symfony.com/doc/current/reference/constraints/Callback.html#the-callback-method</a></li>
  </ol>