Fosuserbundle: Api-platform & FOSUser : service "fos_user.profile.form.factory" non-existent service "form.factory".

Created on 11 Sep 2017  路  5Comments  路  Source: FriendsOfSymfony/FOSUserBundle

Symfony FOSUserBundle versions: 2.0.1
PHP version: 7.1.9
Api platform version: 2.1.0

Description of the problem including expected versus actual behavior:
I am trying to use api-platform with fosuserbundle. I use the docker version 2.1.0 of api-platform, I installed with composer the version 2.0.1 of fosuserbundle. After adding the required configuration in YAML, I have the following error :

The service "fos_user.profile.form.factory" has a dependency on a non-existent service "form.factory". 

I tried many times but always the same error...

Steps to reproduce:

  1. Download the docker version of api platform : https://github.com/api-platform/api-platform/releases/tag/v2.1.0
  2. Install fos user bundle
docker-compose exec app composer require  friendsofsymfony/user-bundle "~2.0"
  1. Add the yaml for fos_user
fos_user:
    db_driver: orm # other valid values are 'mongodb' and 'couchdb'
    firewall_name: main
    user_class: AppBundle\Entity\User
    from_email:
        address: "%mailer_user%"
        sender_name: "%mailer_user%"
  1. Add the user class provided in Api-platform docs
<?php

// src/AppBundle/Entity/User.php

namespace AppBundle\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use FOS\UserBundle\Model\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ORM\Entity
 * @ApiResource(attributes={
 *     "normalization_context"={"groups"={"user", "user-read"}},
 *     "denormalization_context"={"groups"={"user", "user-write"}}
 * })
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @Groups({"user"})
     */
    protected $email;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Groups({"user"})
     */
    protected $fullname;

    /**
     * @Groups({"user-write"})
     */
    protected $plainPassword;

    /**
     * @Groups({"user"})
     */
    protected $username;

    public function setFullname($fullname)
    {
        $this->fullname = $fullname;

        return $this;
    }
    public function getFullname()
    {
        return $this->fullname;
    }

    public function isUser(UserInterface $user = null)
    {
        return $user instanceof self && $user->id === $this->id;
    }
}

  1. Run the symfony console : docker-compose exec app bin/console . Error will appear.

Provide logs (if relevant):

  [Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]                              
  The service "fos_user.profile.form.factory" has a dependency on a non-existent service "form.factory".  


Exception trace:
 () at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:31
 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php:57
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:35
 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php:64
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:35
 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php:57
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:35
 Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php:36
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->process() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:143
 Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:746
 Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:577
 Symfony\Component\HttpKernel\Kernel->initializeContainer() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:119
 Symfony\Component\HttpKernel\Kernel->boot() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:69
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /srv/api-platform/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:125
 Symfony\Component\Console\Application->run() at /srv/api-platform/bin/console:27

Thanks

Most helpful comment

Closed the issue with the help of one member.

It was missing this configuration line :

form: { enabled: true }

Doesn't make sense to not add it by default seriously or have a proper documentation for this.

All 5 comments

Closed the issue with the help of one member.

It was missing this configuration line :

form: { enabled: true }

Doesn't make sense to not add it by default seriously or have a proper documentation for this.

Thanks...

thanks ! ;)

@ntdetect you have to put it in app/config/config.yml

framework:
    form: { enabled: true }

thank youu soo mutch @antoinemineau it's my bad , i forgot a "form: { enabled: false}" in the begin of the code.

Was this page helpful?
0 / 5 - 0 ratings