[英]Create new content using Sonata Admin when mapped entity is an abstract class
I am trying to create new content using Sonata Admin, however due the entity is an abstract class
I am getting on screen a new panel with title Select object type
and the content has a blue box that says No object types available
. 我正在尝试使用Sonata Admin创建新内容,但是由于该实体是一个
abstract class
我在屏幕上看到一个标题为Select object type
的新面板,并且该内容带有一个蓝色框,表示No object types available
。
I don't know what kind of settings I need to set-up in order to be able to select and create one of the entities that are extending my abstract class
. 我不知道我需要进行哪种设置才能选择和创建扩展我的
abstract class
的实体之一。
Any help will be more than welcomed! 任何帮助都将受到欢迎!
AppBundle\\Entity\\AbstractAlert
/**
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(
* name="dtype",
* type="string"
* )
* @ORM\DiscriminatorMap({
* "email" = "AppBundle\Entity\EmailAlert",
* "sms" = "AppBundle\Entity\SmsAlert"
* })
*/
abstract class AbstractAlert
{
}
AppBundle\\Entity\\EmailAlert
class EmailAlert extends AbstractAlert
{
}
AppBundle\\Entity\\SmsAlert
class SmsAlert extends AbstractAlert
{
}
SonataAdminBundle\\Admin\\AlertAdmin
class MassiveAlertAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $form)
{
$form
->with('panel name')
->add('fieldName')
->end();
}
}
This is how it looks my Sonata Admin => Create page 这是我Sonata Admin =>创建页面的外观
If any of you can give me a clue please, I will appreciate it. 如果您能给我一个线索,我将不胜感激。
Thanks in advance for your help, 在此先感谢您的帮助,
Ok, i was wrong and finally found a solution for you ... you have only to choose the abstract entity as you already got and set subclasses via DI as shown here in 16.3 https://sonata-project.org/bundles/admin/2-1/doc/reference/advance.html ... that works like a charm and you'll get your choices in the add button! 好的,我错了,最后为您找到了解决方案...您只需要选择已经获得的抽象实体,然后通过DI设置子类,如16.3 https://sonata-project.org/bundles/admin中所示。 /2-1/doc/reference/advance.html ...就像一个超级按钮一样,您可以在“添加”按钮中进行选择! If not, i could imagine, that every concrete entity class also must have a own admin services, my classes already does.
我可以想象,如果没有,每个具体的实体类也必须具有自己的管理服务,而我的类已经做到了。 And for me: learning never stops ... Sorry for my wrong answer in the previous post ... having this knowledge helps me also now, improving my code.
而对我来说:学习永无止境...很抱歉在上一篇文章中回答错了...现在有了这些知识也对我有所帮助,改善了我的代码。 Thanks for that.
感谢那。
From 11/2018, i have the same problem but i use yaml to the config of the services. 从11/2018起,我有同样的问题,但是我使用yaml来配置服务。
The class 'Operation' is the abstract one. “操作”类是抽象类。
Here is a example with yaml 这是yaml的例子
app.admin.operation:
class: App\Admin\OperationAdmin
arguments: [~, App\Entity\Operation, ~]
tags:
- { name: sonata.admin, manager_type: orm, group: "app.admin.group.operation", label: Operation }
calls:
- [ setSubClasses, [{ TeamOperation: App\Entity\TeamOperation, Staff: App\Entity\StaffOperation, PlayersOperation: App\Entity\PlayersOperation} ]]
Whit this type of configuration you can select the type of 'Operation' between that 3 entities. 如果您使用这种类型的配置,则可以在这3个实体之间选择“操作”类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.