Search code examples
phpsymfonysymfony4easyadmin

The configuration of the "App\Entity\Cat" entity is not available (this entity is used as the target of the "cat" autocomplete field)


I'm trying to configure EasyAdmin back-end with Symfony 4.

However, when I try to edit a post, I get:

The configuration of the "App\Entity\Cat" entity is not available (this entity is used as the target of the "cat" autocomplete field).

I've tried with another entity (User) and it works perfectly.

Do you guys have any idea of what this configuration is and/or how to make it available ? Thanks.

This is the actual configuration:

formats:
    blabla

entities:
    User:
        class: App\Entity\User
        list:
            fields: ['username', 'roles', 'email', 'registration_datetime', 'status']

    Post:
        class: App\Entity\Post
        list:
            fields: blabla

        edit:
            fields:
                - {type: 'group', columns: 9}
                - {property: 'title', type_options: { block_name: 'custom_title' }}
                - {property: 'body', type: 'fos_ckeditor'}
                - {type: 'group', columns: 3}
                - {property: 'cat', type: 'easyadmin_autocomplete', type_options: {class: 'App\Entity\Cat'}}
                - {property: 'subcat', type: 'easyadmin_autocomplete', type_options: {class: 'App\Entity\Subcat'}}
                - 'tile'
                - 'place'

site_name: 'ShadowTech'

user:
    name_property_path: 'username'

Below is the Cat entity:

<?php

namespace App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\CatRepository")
 */
class Cat
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $name;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Post", mappedBy="cat")
     */
    private $posts;

    /**
     * @ORM\Column(type="string", length=100)
     */
    private $readable_name;

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

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function __toString()
    {
        return $this->getReadableName();
    }

    /**
     * @return Collection|Post[]
     */
    public function getPosts(): Collection
    {
        return $this->posts;
    }

    public function addPost(Post $post): self
    {
        if (!$this->posts->contains($post)) {
            $this->posts[] = $post;
            $post->setCat($this);
        }

        return $this;
    }

    public function removePost(Post $post): self
    {
        if ($this->posts->contains($post)) {
            $this->posts->removeElement($post);
            // set the owning side to null (unless already changed)
            if ($post->getCat() === $this) {
                $post->setCat(null);
            }
        }

        return $this;
    }

    public function getReadableName(): ?string
    {
        return $this->readable_name;
    }

    public function setReadableName(string $readable_name): self
    {
        $this->readable_name = $readable_name;

        return $this;
    }
}

Solution

  • So, as mentioned in comments - you just need to add configuration for this Entity to easy_admin.yaml.

    Like that:

    #config/packages/easy_admin.yaml
    easy_admin:
      entities:
        Cat:
          class: App\Entity\Cat