I'm trying to save a form of my comment entity. Comment entity is related with post entity.
I can't preset the ID of the post in the CommentType then I read in the docs about to create a custom Factory Method. But is not explained how to create, just how to configure. I think about i need make one method to take the Post Slug's and save when the form is send.
I was looking into the code of your bundles and I find an example.
I made my own Factory and FactoryInterface.
My Factory looks like this:
class CommentFactory implements CommentFactoryInterface
{
/**
* @var FactoryInterface
*/
private $factory;
/**
* @param FactoryInterface $factory
*/
public function __construct(FactoryInterface $factory)
{
$this->factory = $factory;
}
/**
* {@inheritDoc}
*/
public function createNew()
{
return $this->factory->createNew();
}
public function createWithPost($postId)
{
$comment = $this->createNew();
$comment->setPost($postId);
return $comment;
}
}
Now I can't find how to inject the FactoryInterface of Sylius ResourceBundle.
Any tip?
comment_create:
path: /new/{postId}
methods: [GET, POST]
defaults:
_controller: acme.controller.comment:createAction
_sylius:
template: "..."
factory:
method: createWithPost
arguments: [$postId]
Does that work for you in routing?
We can move this conversation to stackoverflow. I have posted some brief explantation of factory decoration there.
Probably can be closed.
Most helpful comment
We can move this conversation to stackoverflow. I have posted some brief explantation of factory decoration there.
Probably can be closed.