【问题标题】:sonata admin many_to_one editable do not work奏鸣曲管理员 many_to_one 可编辑不起作用
【发布时间】:2019-02-12 16:02:06
【问题描述】:

实体定义

 /**
     * @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,
            ])

结果

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

我在奏鸣曲模板中搜索 vendor/sonata-project/admin-bundle/src/Resources/views/CRUD/base_list_field.html.twig - 此字段具有可编辑的 true 但 xEditableType 为空。

【问题讨论】:

    标签: sonata-admin symfony4


    【解决方案1】:

    正如您在 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 %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-30
      • 2019-01-14
      • 2018-08-11
      • 2018-03-22
      • 2016-08-18
      • 2012-01-07
      • 1970-01-01
      • 2014-08-03
      相关资源
      最近更新 更多