wyllyjon
wyllyjon

Reputation: 493

Create a custom resource form on Sylius (Symfony3) : "Expected scalar, but got array"

I try to create a custom form for my Sylius Resource "article" using the Sylius doc. Without creating custom form, everything works well, but if I want to make a custom form, I have this error "Invalid type for path "sylius_resource.resources.blog.article.classes.form". Expected scalar, but got array."

Here is my ArticleType class :

<?php

namespace BlogAdminBundle\Form\Type;

use Symfony\Component\Form\FormBuilderInterface;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;

class ArticleType extends AbstractResourceType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        // Build your custom form!
        $builder->add('id', HiddenType::class)
            ->add('titre', TextType::class)
            ->add('date', DateType::class, array('html5' => true))
            ->add('contenu', CKEditorType::class)
            ->add('tags', TextType::class)
            ->add('resume', TextareaType::class)
            ->add('save', SubmitType::class, array('label' => 'Enregistrer l\'article'));
    }

    public function getName()
    {
        return 'admin_article';
    }
}

And the declaration of my resource :

sylius_resource:
    resources:
        blog.article:
            driver: doctrine/orm
            classes:
                model: BlogBundle\Entity\Article
                form:
                    default: BlogAdminBundle\Form\Type\ArticleType

Does anyone know what is the problem ?

Thanks everyone !

Upvotes: 0

Views: 918

Answers (1)

Ivan Matas
Ivan Matas

Reputation: 128

you have to register your form as form.type service. And you have to send argument of your form class. You should do something like this:

services:
    app.form.type.article:
        class: BlogAdminBundle\Form\Type\ArticleType
        arguments: [BlogBundle\Entity\Article]
        tags:
            - { name: form.type }

You can check what classes are used for your Article by using this command: php bin/console debug:container | grep article

Upvotes: 4

Related Questions