sonata-project/SonataAdminBundle — pull request #815 by michelsalib (2012-06-09 11:59:32+00:00)
Title: [WIP] Support for inherited classes

@rande like I said yesterday, I cleaned my code in order to submit a 'clean 'proposal.

You just have to extend `InheritanceAdmin` instead of `Admin` and the declare your service as follow:
``` xml

BCC\TestBundle\Entity\Base

BCC\TestBundle\Entity\Student
BCC\TestBundle\Entity\Teacher

```
The only thing that changes is the last argument which is the list of supported subclasses, keys are used to render label (for the moment).

In order to support different forms, you can simply do:
``` php
getSubject();

if ($subject instanceof Teacher) {
$form->add('course', 'text');
}
elseif ($subject instanceof Student) {
$form->add('year', 'integer');
}

$form->add('name');
}
```

**I want to have some feedback before cleaning and documenting the code.**
- Things are a bit hackish for the moment, do we need to refactor the `Admin` class in order to have a cleaner override (because this one duplicates code and forgets about the ModelManager).
- Currently the subclasses are given trough configuration, what do you think about an abstract method in the `InheritanceAdmin` that asks for the subclasses? It will be helpful to specify better label or other behavior later. The Doctrine Orm Admin bundle could also provide a default implementation later from the discriminator map.