Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BAP-18759: Upgrade to Symfony 3.4.27 (master) (#23502)
* BAP-18759: Upgrade to Symfony 3.4.27 Co-authored-by: Vitaliy Berdylo Co-authored-by: Vova Soroka Co-authored-by: Eugene Chetverikov Co-authored-by: Vladimir Seniuk Co-authored-by: Ruslan Panasiuk
- Loading branch information
1 parent
94db83d
commit a75d9a2
Showing
25 changed files
with
409 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Oro/Bundle/ProductBundle/Form/DataTransformer/ProductImageTypesTransformer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
|
||
namespace Oro\Bundle\ProductBundle\Form\DataTransformer; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Symfony\Component\Form\DataTransformerInterface; | ||
|
||
/** | ||
* Transforms an NULL to empty array and ArrayCollection to array. | ||
*/ | ||
class ProductImageTypesTransformer implements DataTransformerInterface | ||
{ | ||
/** | ||
* @param mixed $value | ||
* @return array | ||
*/ | ||
public function transform($value): array | ||
{ | ||
if ($value instanceof ArrayCollection) { | ||
return $value->toArray(); | ||
} | ||
|
||
return []; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* @return array | ||
*/ | ||
public function reverseTransform($value): array | ||
{ | ||
// Data should not be transformed | ||
return $value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/Oro/Bundle/ProductBundle/Form/Type/ProductImageTypesType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Oro\Bundle\ProductBundle\Form\Type; | ||
|
||
use Oro\Bundle\LayoutBundle\Model\ThemeImageType; | ||
use Oro\Bundle\ProductBundle\Form\DataTransformer\ProductImageTypesTransformer; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\OptionsResolver\Options; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* Responsible for product image types. | ||
*/ | ||
class ProductImageTypesType extends AbstractType | ||
{ | ||
/** | ||
* @param FormBuilderInterface $builder | ||
* @param array $options | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$builder->addModelTransformer(new ProductImageTypesTransformer()); | ||
} | ||
|
||
/** | ||
* @param OptionsResolver $resolver | ||
*/ | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver | ||
->setRequired('image_types') | ||
->setAllowedTypes('image_types', 'array') | ||
->setDefaults([ | ||
'multiple' => true, | ||
'choices' => function (Options $options) { | ||
$typesKeys = array_map(function (ThemeImageType $imageType) { | ||
return $imageType->getName(); | ||
}, $options['image_types']); | ||
|
||
return array_combine($typesKeys, $typesKeys); | ||
} | ||
]); | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getParent(): string | ||
{ | ||
return ChoiceType::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Oro/Bundle/ProductBundle/Tests/Unit/Form/Type/ProductImageTypesTypeTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Oro\Bundle\ProductBundle\Tests\Unit\Form\Type; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Oro\Bundle\LayoutBundle\Model\ThemeImageType; | ||
use Oro\Bundle\ProductBundle\Form\Type\ProductImageTypesType; | ||
use Symfony\Component\Form\Test\FormIntegrationTestCase; | ||
|
||
class ProductImageTypesTypeTest extends FormIntegrationTestCase | ||
{ | ||
/** | ||
* @param array|null $defaultData | ||
* @param array|null $submittedData | ||
* @param array $expectedTypes | ||
* @param array $options | ||
* @dataProvider submitDataProvider | ||
*/ | ||
public function testSubmit($defaultData, $submittedData, $expectedTypes, array $options): void | ||
{ | ||
$form = $this->factory->create(ProductImageTypesType::class, $defaultData, $options); | ||
$this->assertEquals($defaultData, $form->getData()); | ||
|
||
$form->submit($submittedData); | ||
$this->assertTrue($form->isValid()); | ||
$this->assertEquals($expectedTypes, $form->getData()); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function submitDataProvider(): array | ||
{ | ||
$imageTypes = [ | ||
new ThemeImageType('main', 'Main', []), | ||
new ThemeImageType('listing', 'Listing', []), | ||
new ThemeImageType('additional', 'Additional', []), | ||
]; | ||
|
||
return [ | ||
'without default data' => [ | ||
'defaultData' => null, | ||
'submittedData' => [ | ||
'main', | ||
'listing' | ||
], | ||
'expectedTypes' => ['main', 'listing'], | ||
'options' => ['image_types' => $imageTypes] | ||
], | ||
'with default data' => [ | ||
'defaultData' => new ArrayCollection(['main', 'listing', 'additional']), | ||
'submittedData' => [ | ||
'main', | ||
], | ||
'expectedTypes' => ['main'], | ||
'options' => ['image_types' => $imageTypes] | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.