Skip to content

Commit

Permalink
Merge pull request Sylius#71 from TheMadeleine/image-validation
Browse files Browse the repository at this point in the history
[CJMAX-51] CarouselItem image validation
  • Loading branch information
michalmarcinkowski committed May 5, 2016
2 parents fcecad9 + a12a335 commit 5a8f979
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/AppBundle/Form/Type/CarouselItemType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Magdalena Banasiak <magdalena.banasiak@lakion.com>
Expand All @@ -24,6 +26,27 @@ public function buildForm(FormBuilderInterface $builder, array $options)
;
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
'data_class' => $this->dataClass,
'validation_groups' => function (FormInterface $form) {
$data = $form->getData();
$validationGroups = $this->validationGroups;
if (null !== $data && null === $data->getId()) {
$validationGroups[] = 'carousel_item_create';
}

return $validationGroups;
},
])
;
}

/**
* {@inheritdoc}
*/
Expand Down
6 changes: 6 additions & 0 deletions src/AppBundle/Resources/config/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ AppBundle\Entity\ProductGridItem:
- NotBlank: ~
product:
- NotBlank: ~

AppBundle\Entity\CarouselItem:
properties:
file:
- NotBlank: { groups: ['carousel_item_create'] }
- Image: { groups: ['carousel_item_create'] }

0 comments on commit 5a8f979

Please sign in to comment.