-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use form factory when extending controller #684
Comments
i have the same issue ? |
Its related #681 @jyyyy temporary solution: use FOS\CommentBundle\Controller\ThreadController as BaseThreadController;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ThreadController extends BaseThreadController
{
protected $container;
public function __construct(ContainerInterface $container)
{
// Override container
$this->container = $container;
}
public function setContainer(\Psr\Container\ContainerInterface $container)
{
}
} |
You will have to inject the use FOS\CommentBundle\Controller\ThreadController;
use FOS\CommentBundle\FormFactory\CommentFormFactory;
class CustomThreadController extends BaseThreadController
{
private $formFactory;
public function __construct(CommentFormFactory $formFactory)
{
$this->formFactory = $formFactory;
}
} |
Another solution that might work is adding a use FOS\CommentBundle\Controller\ThreadController;
use FOS\CommentBundle\FormFactory\CommentFormFactory;
class CustomThreadController extends BaseThreadController
{
public static function getSubscribedServices(): array
{
$services = parent::getSubscribedServices();
$services['fos_comment.form_factory.comment'] = CommentFormFactory::class;
return $services;
}
} Note: this probably won't work if you use a custom comment form factory. |
@XWB, should then method
|
The |
@XWB Even though I understand that dependency injection is the correct way to solve this. Your solution still gives me an error message;
The reason I posted it here instead of StackOverflow is because this error only occurred after updating from 2.2.x to 2.3.x Even though a workaround would help me personally, I think this might be a bug since the upgrade is not backwards compatible in this particular situation. Loving this bundle though, and thanks for taking the time to respond so quickly! I really appreciate it. |
Is there maybe any update regarding this issue? |
any update??? |
When extending the
FOS\CommentBundle\Controller\ThreadController
class and overriding thenewThreadCommentsAction
I'm not able to use the$this->container->get('fos_comment.form_factory.comment')
like it is called in the parent method.The error returned is;
Service "fos_comment.form_factory.comment" not found: even though it exists in the app's container, the container inside "App\Controller\ThreadController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session", "templating" and "twig" services. Try using dependency injection instead.
I'm using Symfony 4.2 with FOSCommentBundle 2.3. Up till FOSCommentBundle 2.2 this did work. Therefor it seems like it might be a BC-break.
The text was updated successfully, but these errors were encountered: