/** * {@inheritdoc} */ public function reverseTransform($value) { if (null === $value) { return null; } $class = $this->repository->getClassName(); Assert::isInstanceOf($value, $class); $accessor = PropertyAccess::createPropertyAccessor(); return $accessor->getValue($value, $this->identifier); }
/** * {@inheritdoc} */ public function reverseTransform($value) { if (null === $value) { return null; } $resource = $this->repository->findOneBy([$this->identifier => $value]); if (null === $resource) { throw new TransformationFailedException(sprintf('Object "%s" with identifier "%s"="%s" does not exist.', $this->repository->getClassName(), $this->identifier, $value)); } return $resource; }
function it_reverse_transform_resource_to_identifier(RepositoryInterface $repository, FakeEntity $value) { $repository->getClassName()->willReturn(FakeEntity::class); $value->getId()->willReturn(6); $this->reverseTransform($value)->shouldReturn(6); }
function it_transforms_resource_in_identifier(RepositoryInterface $repository, ResourceInterface $resource) { $repository->getClassName()->willReturn(ResourceInterface::class); $resource->getId()->willReturn(6); $this->transform($resource)->shouldReturn(6); }
function let(RepositoryInterface $repository) { $repository->getClassName()->willReturn('spec\\Sylius\\Bundle\\ResourceBundle\\Form\\DataTransformer\\FakeEntity'); $this->beConstructedWith($repository, 'id'); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('groups', 'sylius_group_from_identifier', ['label' => 'sylius.form.action.customer_group', 'property' => 'name', 'class' => $this->groupRepository->getClassName(), 'constraints' => [new NotBlank(), new Type(['type' => 'numeric'])]]); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('group', CustomerGroupCodeChoiceType::class, ['label' => 'sylius.form.promotion_action.customer_group', 'property' => 'name', 'class' => $this->groupRepository->getClassName(), 'constraints' => [new NotBlank(['groups' => ['sylius']]), new Type(['type' => 'numeric', 'groups' => ['sylius']])]]); }