简体   繁体   English

Easyadmin一对多:不显示表单

[英]Easyadmin One-to-Many: not displaying form

With Easyadmin, Symfony3 and Doctrine I'm trying to display an embedded form for an Article to add Urls to itself. 我正在尝试使用Easyadmin,Symfony3和Doctrine来显示文章的嵌入式表单,以向其自身添加Urls。

However, the article form currently does not show the UrlType form, but instead text boxes which - what it seems - expect Ids of the Urls I would like to add. 但是,该文章表单当前不显示 UrlType表单,而是显示文本框,该文本框(看起来似乎)期望我要添加的Urls的ID。

在此处输入图片说明

I found that the following configuration should be working (according to this question ): 我发现以下配置应该可以正常工作(根据此问题 ):

       form:
            fields:
                [...]
                - { property: 'urls', type: 'collection', type_options: { entry_type: 'MyVendor\MyBundle\Form\UrlType', by_reference: false }  }

Article: 文章:

class Article
{
    [..]  

    /**
     * @ORM\OneToMany(targetEntity="Url", mappedBy="article", cascade={"persist", "remove"})
     */
    private $urls;

    public function __construct() {
        $this->urls = new ArrayCollection();
    }

    /**
     * Add url
     *
     * @param Url $url
     *
     * @return Article
     */
    public function addUrl(Url $url)
    {
        $url->setArticle($this);

        $this->urls[] = $url;

        return $this;
    }

    /**
     * Remove url
     *
     * @param Url $url
     */
    public function removeUrl(Url $url)
    {
        $this->urls->removeElement($url);
    }

    /**
     * Get url
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getUrls()
    {
        return $this->urls;
    }
}

Url: 网址:

class Url
{
   [..]  

    /**
     * @var Article
     *
     * @ORM\ManyToOne(targetEntity="Article", inversedBy="urls")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="article_id", referencedColumnName="id")
     * })
     */
    private $article;


    /**
     * Set article
     *
     * @param Article $article
     *
     * @return Url
     */
    public function setArticle(Article $article = null)
    {
        $this->article = $article;

        return $this;
    }

    /**
     * Get article
     *
     * @return Article
     */
    public function getArticle()
    {
        return $this->article;
    }
}

UrlType: UrlType:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('address', TextType::class);
    $builder->add('description', TextType::class);
}

I have checked, double checked and tried so many things in the code and searched google as well as stackoverflow. 我已经检查,仔细检查并尝试了代码中的许多内容,并搜索了google和stackoverflow。

How can I display fields to add new URLs to the Article? 如何显示字段以向文章添加新的URL?

Thanks to the friendly folks at EasyAdmin this issue has been resolved. 感谢EasyAdmin的友好伙伴,此问题已得到解决。 It turns out that despite of using the fully qualified namespace to UrlType in YAML config, the type is overwritten with the Symfony UrlType . 事实证明,尽管在YAML配置中对UrlType使用了完全限定的名称空间,但该类型仍被Symfony UrlType覆盖。

Solution : Rename MyVendor\\MyBundle\\Form\\UrlType to for example MyVendor\\MyBundle\\Form\\UrlEntityType 解决方案 :将MyVendor\\MyBundle\\Form\\UrlType重命名为例如MyVendor\\MyBundle\\Form\\UrlEntityType

This looks like a bug in either Symfony or EasyAdmin. 这看起来像Symfony或EasyAdmin中的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM