This bundle use coosos/jms-serializer-bidirectional-relation
package, see the documentation for more configuration.
For your model to work with bundle, is necessary to use VersionWorkflowTrait.
/**
* @Coosos\BidirectionalRelation\Annotations\SerializerBidirectionalRelation()
*/
class News
{
use \Coosos\VersionWorkflowBundle\Model\VersionWorkflowTrait;
}
Note: With doctrine, is necessary to update schema
public function __construct(Coosos\VersionWorkflowBundle\Service\VersionWorkflowService $versionWorkflowService)
{
$this->versionWorkflowService = $versionWorkflowService;
}
public function add()
{
$news = ....
$news->setTitle('Hello world');
$workflowName = 'news_process';
$transition = 'to_review'; // Use null for use initialized place
$versionWorkflowModel = $this->versionWorkflowService->applyTransitionAndTransformToVersionWorkflow(
$news,
$workflowName,
$transition
);
}
Note : If use with doctrine, this entity getting is fake object, but is transform for doctrine in prePersist event
public function get($id)
{
$versionWorkflowModel = ...
$news = $this->versionWorkflowService->transformToObject($versionWorkflowModel);
$news->getTitle();
$transition = 'publish';
// Update and transform to version workflow
$versionWorkflowModel = $this->versionWorkflowService->applyTransitionAndTransformToVersionWorkflow(
$news,
$workflowName,
$transition
);
}