我想构建一个特殊的表单来管理 LogEntry 实体(来自Loggable Behavioral)并处理实体恢复以允许管理员将某些实体恢复到旧版本。
我尝试使用下一个 FormType 生成一个表单,其中包含分配给该特定 LogEntry 的实体版本列表:
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Gedmo\Loggable\Entity\Repository\LogEntryRepository as EntityRepository;
class LogItemVersionsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
// In that point, I would need the entity assigned to that specific LogEntry to be able to load the diferent versions
$entity = $builder->getData();
//var_dump($data);
$builder
->add('version', 'entity', array(
'class' => 'Gedmo\Loggable\Entity\LogEntry',
'property' => 'version',
'query_builder' => function(EntityRepository $er) {
return $er->getLogEntriesQuery($entity);
},
))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Gedmo\Loggable\Entity\LogEntry'
));
}
public function getName()
{
return 'zashost_zaspanelbundle_logitemversionstype';
}
}
但我有以下疑问:
- LogEntry 没有检索记录对象的方法。我应该创建一个继承 LogEntry 的中间类来添加该方法吗?请注意,分配给 LogEntry 的实体是可变的,那么我应该将该方法放在 LogEntry 实体类中吗?