Entity definition
You can store these kinds as constants in entity class.
class Foo
{
const KIND_1 = 1;
const KIND_2 = 2;
const KIND_3 = 3;
//...
/**
* @ORM\Column(type="smallint")
*/
protected $kind;
}
Note that constants are integers, so they are easy stored in database. I used smallint because it's the smallest integer available in Doctrine2.
Form
Create new form field for kind:
class KindChoiceType extends AbstractType
{
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$class = new \ReflectionClass('Namespace\Bar\Foo');
$resolver->setDefaults(array(
'choices' => array_flip($class->getConstants()),
'translation_domain' => 'kinds'
));
}
public function getName()
{
return 'kind_choice';
}
public function getParent()
{
return 'choice';
}
}
'Namespace\Bar\Foo' is full name of your entity class with namespace. (Note that work only because all constants in class are kinds. If you will add another constants, you must modify that code.)
Now create translation files for all languages of your website. I usually create YAML file. For English it should look like:
# YOUR_BUNDLE/Resources/translations/kinds.en.yml
KIND_1: first kind
KIND_2: kind no. 2
KIND_3: next kind
# ...
Now pass your new field type instead of 'choice' when you create form for your Foo entity:
->add('kind', new KindChoiceType());