0
votes

Entity definition

 /**
     * @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;

Admin definition

protected function configureListFields(ListMapper $listMapper)
    {

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

Result enter image description here

Field is not editable - tags is shown as href to edit one tag.

Im search in sonata templates vendor/sonata-project/admin-bundle/src/Resources/views/CRUD/base_list_field.html.twig - this field has editable true but xEditableType is null.

1

1 Answers

0
votes

As you can see in the github Repository, the many-to-one list field is not editable at all.

The editable => true does nothing, and the multiple => true is not usefull because it's a many to one relation...

Here is the code of this list field :

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 %}