0

I get

Expected argument of type "App\Entity\ObjectxDescription", "string" given at property path "description".

When I try to save data from TextEditorField, I get the error above. The field displays the content correctly and is defined in the Crud Controller. I create CRUD Controller with form to edit Name and Description. Name variable is in Objectx Entity and Description in ObjectxDescription Entity.

crud controller:

<?php
//src/Controller/Admin/ObjectxCrudController.php

namespace App\Controller\Admin;

use App\Entity\Objectx;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;

use App\Entity\ObjectxDescription;

class ObjectxCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Objectx::class;
    }

    public function configureCrud(Crud $crud): Crud
    {
        return $crud
            ->setEntityLabelInSingular('Object')
            ->setEntityLabelInPlural('Objects')
            ->setPageTitle('index', 'Objects')
        ;
    }

    public function configureFields(string $pageName): iterable
    {
        return [
            TextField::new('name','Name'),
            TextEditorField::new('description','Description')
        ];
    }
}

Objectx entity:

<?php
//src/Entity/Objectx.php

namespace App\Entity;

use App\Repository\ObjectxRepository;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=ObjectxRepository::class)
 */
class Objectx
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

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

    /**
     * @ORM\OneToOne(targetEntity=ObjectxDescription::class, cascade={"persist", "remove"})
     * @ORM\JoinColumn(nullable=false)
     */
    private $description;

    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 getDescription(): ?ObjectxDescription
    {
        return $this->description;
    }

    public function setDescription(ObjectxDescription $description): self
    {
        $this->description = $description;

        return $this;
    }
}

ObjectxDescription entity:

<?php
// src/Entity/ObjectxDescription.php

namespace App\Entity;

use App\Repository\ObjectxDescriptionRepository;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=ObjectxDescriptionRepository::class)
 */
class ObjectxDescription
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $description;

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

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

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function setDescription(?string $description): self
    {
        $this->description = $description;

        return $this;
    }
}
Dhia Djobbi
  • 1,176
  • 2
  • 15
  • 35
Tadeusz Majkowski
  • 612
  • 2
  • 8
  • 26
  • Your description is in other entity so you need to create form for that entity and use it like in this answer https://stackoverflow.com/a/67938503/9807055 – Flash Aug 06 '21 at 20:25
  • Thanks for your reply @Flash i add this setting to text field from other entity but get the same error TextEditorField::new('description')->setFormTypeOptions(['by_reference' => false])->setCustomOptions(['entryType' => ObjectxDescription::class])]; – Tadeusz Majkowski Aug 15 '21 at 16:25

0 Answers0