奏鸣曲管理员many_to_one可编辑不起作用

时间:2018-09-07 10:04:04

标签: sonata-admin symfony4

实体定义

 /**
     * @var ArrayCollection|Keyword
     * @ORM\ManyToMany(targetEntity="Mea\KeywordsBundle\Entity\Keyword",cascade={"persist"})
     * @ORM\JoinTable(
     *      joinColumns={@ORM\JoinColumn(name="log_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="keyword_id", referencedColumnName="id")}
     * )
     */
    protected $tags;

管理员定义

protected function configureListFields(ListMapper $listMapper)
    {

      ->add('tags','many_to_one',[
                'editable' => true,
                'multiple'=>true,
                'class' => Keyword::class,
            ])

结果 enter image description here

该字段不可编辑-标签显示为href,以编辑一个标签。

我在奏鸣曲模板中搜索供应商/sonata-project/admin-bundle/src/Resources/views/CRUD/base_list_field.html.twig-此字段为true,但xEditableType为null。

1 个答案:

答案 0 :(得分:0)

如您在github存储库中所见,多对一列表字段根本不可编辑。

editable => true不执行任何操作,而multiple => true则无用,因为它与许多一对关系...

这是此列表字段的代码:

https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Resources/views/CRUD/Association/list_many_to_one.html.twig

{% block field %}
    {% if value %}
        {% set route_name = field_description.options.route.name %}
        {% if not field_description.options.identifier|default(false)
            and field_description.hasAssociationAdmin
            and field_description.associationadmin.hasRoute(route_name)
            and field_description.associationadmin.hasAccess(route_name, value)
            and field_description.associationadmin.id(value)
        %}
            <a href="{{ field_description.associationadmin.generateObjectUrl(route_name, value, field_description.options.route.parameters) }}">
                {{ value|render_relation_element(field_description) }}
            </a>
        {% else %}
            {{ value|render_relation_element(field_description) }}
        {% endif %}
    {% endif %}
{% endblock %}