-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Integration with a Symfony Workflow component #71
Labels
Comments
It will be really nice feature :) 👍 |
Ok It's possible. In workflow configuration You must indicate Your custom marking store: marking_store:
service: App\Service\MarkingStore And here is code of this class <?php
/**
* @author Jakub Cegiełka <kuba.ceg@gmail.com>
*/
namespace App\Service;
use App\Entity\Offer\OfferStatus;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\Workflow\Marking;
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
class MarkingStore implements MarkingStoreInterface
{
private $property;
private $propertyAccessor;
/**
* @param string $property
* @param PropertyAccessorInterface|null $propertyAccessor
*/
public function __construct($property = 'status', PropertyAccessorInterface $propertyAccessor = null)
{
$this->property = $property;
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
}
/**
* {@inheritdoc}
*/
public function getMarking($subject)
{
$placeName = $this->propertyAccessor->getValue($subject, $this->property);
$placeName = OfferStatus::getReadableValue($placeName);
if (!$placeName) {
return new Marking();
}
return new Marking(array($placeName => 1));
}
/**
* {@inheritdoc}
*/
public function setMarking($subject, Marking $marking)
{
$value = key($marking->getPlaces());
$placeValue = OfferStatus::getChoices()[$value];
$this->propertyAccessor->setValue($subject, $this->property, $placeValue);
}
} As You see in constructor I've indicated column name with our enum type (property arg). If there (in wolkflow component) will be possibility to select column with our field this service can be automated. At this moment it's not possible. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Symfony Workflow component appeared in version 3.2. It is the implementation of the state machine. As ENUM fields in database often used for keeping some readable statuses, so it would be nice to add state machine over these types in PHP.
I am not sure if this integration is possible. But want to investigate.
The text was updated successfully, but these errors were encountered: