From a93d010acebb9d46c67c30aa95ac759af6801581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Raye=CC=81?= Date: Fri, 26 Apr 2019 13:06:10 +0200 Subject: [PATCH 1/2] Update composer.json for compatibility with akeneo-labs/custom-entity-bundle 3.* --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ed74d8c..5a050a1 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,7 @@ } ], "require": { - "akeneo/pim-community-dev": "2.*", - "akeneo-labs/custom-entity-bundle": "~2.1|~2.2|~2.4" + "akeneo-labs/custom-entity-bundle": "~2.1|~2.2|~2.4|~3.0" }, "autoload": { "psr-4": { From cfa8c0ea0a60613c5032ffdeff34f467613dc98a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Raye=CC=81?= Date: Mon, 29 Apr 2019 11:50:01 +0200 Subject: [PATCH 2/2] TASK: Update source code for compatibility with custom entity bundle version 3.0. Not compatible with previous version --- EventListener/FilePersister.php | 7 ++- Form/EventListener/PicturedFormListener.php | 13 +++-- .../TranslatableFieldSubscriber.php | 48 ++++++++++++------- Form/Type/MediaType.php | 2 +- Form/Type/TranslatableType.php | 18 ++----- Model/CustomEntityTrait.php | 4 +- Model/DescribedInterface.php | 2 +- Model/DescribedTrait.php | 2 +- Model/DescribedTranslationInterface.php | 2 +- Model/LabeledInterface.php | 2 +- Model/LabeledTrait.php | 2 +- Model/LabeledTranslationInterface.php | 6 ++- Model/PicturedInterface.php | 4 +- Model/PicturedTrait.php | 4 +- Model/PicturedTranslationInterface.php | 8 +++- Model/PicturedTranslationTrait.php | 2 +- Model/ReferenceDataTrait.php | 1 - Model/TranslatableCustomEntityTrait.php | 2 - Provider/Field/TranslatableFieldProvider.php | 2 +- Repository/ChoicesRepository.php | 3 -- Resources/config/form_types.yml | 3 +- Utils/FileInfoUtils.php | 6 +-- composer.json | 4 +- 23 files changed, 79 insertions(+), 68 deletions(-) diff --git a/EventListener/FilePersister.php b/EventListener/FilePersister.php index b8384d9..b47ecac 100644 --- a/EventListener/FilePersister.php +++ b/EventListener/FilePersister.php @@ -2,8 +2,7 @@ namespace Kiboko\Bundle\EnrichBundle\EventListener; -use Akeneo\Component\FileStorage\Model\FileInfoInterface; -use Kiboko\Bundle\EnrichBundle\Entity\Translatable; +use Akeneo\Tool\Component\FileStorage\Model\FileInfoInterface; use Kiboko\Bundle\EnrichBundle\Model\PicturedInterface; use Kiboko\Bundle\EnrichBundle\Model\PicturedTranslationInterface; use League\Flysystem\Filesystem; @@ -22,6 +21,8 @@ public function __construct(Filesystem $filesystem) /** * @param GenericEvent $event + * + * @throws \League\Flysystem\FileExistsException */ public function onAkeneoStoragePostsave(GenericEvent $event) { @@ -55,6 +56,8 @@ public function onAkeneoStoragePostsave(GenericEvent $event) /** * @param FileInfoInterface $picture * @param UploadedFile $file + * + * @throws \League\Flysystem\FileExistsException */ private function persistFile(FileInfoInterface $picture, UploadedFile $file) { diff --git a/Form/EventListener/PicturedFormListener.php b/Form/EventListener/PicturedFormListener.php index 64723d2..782716e 100644 --- a/Form/EventListener/PicturedFormListener.php +++ b/Form/EventListener/PicturedFormListener.php @@ -2,11 +2,10 @@ namespace Kiboko\Bundle\EnrichBundle\Form\EventListener; -use Akeneo\Component\FileStorage\Model\FileInfoInterface; - +use Akeneo\Tool\Component\FileStorage\Model\FileInfoInterface; use Kiboko\Bundle\EnrichBundle\Model\PicturedInterface; use Kiboko\Bundle\EnrichBundle\Model\PicturedTranslationInterface; -use Kiboko\Bundle\EnrichBundle\Utils\FileInfo; +use Kiboko\Bundle\EnrichBundle\Utils\FileInfoUtils; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -14,16 +13,16 @@ class PicturedFormListener implements EventSubscriberInterface { /** - * @var FileInfo + * @var FileInfoUtils */ private $utils; /** * FormListener constructor. * - * @param FileInfo $utils + * @param FileInfoUtils $utils */ - public function __construct(FileInfo $utils) + public function __construct(FileInfoUtils $utils) { $this->utils = $utils; } @@ -34,7 +33,7 @@ public function __construct(FileInfo $utils) public static function getSubscribedEvents() { return [ - FormEvents::POST_SUBMIT => 'postSubmit' + FormEvents::POST_SUBMIT => 'postSubmit', ]; } diff --git a/Form/Subscriber/TranslatableFieldSubscriber.php b/Form/Subscriber/TranslatableFieldSubscriber.php index b82fd46..5b297aa 100644 --- a/Form/Subscriber/TranslatableFieldSubscriber.php +++ b/Form/Subscriber/TranslatableFieldSubscriber.php @@ -2,11 +2,10 @@ namespace Kiboko\Bundle\EnrichBundle\Form\Subscriber; -use Akeneo\Component\Localization\Factory\TranslationFactory; +use Akeneo\Platform\Bundle\UIBundle\Exception\MissingOptionException; +use Akeneo\Tool\Component\Localization\Factory\TranslationFactory; +use Akeneo\UserManagement\Bundle\Context\UserContext; use Doctrine\Common\Inflector\Inflector; -use Pim\Bundle\CatalogBundle\Helper\LocaleHelper; -use Pim\Bundle\EnrichBundle\Exception\MissingOptionException; -use Pim\Bundle\UserBundle\Context\UserContext; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormEvent; @@ -37,11 +36,6 @@ class TranslatableFieldSubscriber implements EventSubscriberInterface */ protected $options; - /** - * @var LocaleHelper - */ - protected $localeHelper; - /** * @var UserContext */ @@ -51,22 +45,21 @@ class TranslatableFieldSubscriber implements EventSubscriberInterface * Constructor * * @param FormFactoryInterface $formFactory - * @param ValidatorInterface $validator - * @param UserContext $userContext - * @param LocaleHelper $localeHelper - * @param array $options + * @param ValidatorInterface $validator + * @param UserContext $userContext + * @param array $options + * + * @throws MissingOptionException */ public function __construct( FormFactoryInterface $formFactory, ValidatorInterface $validator, UserContext $userContext, - LocaleHelper $localeHelper, array $options ) { $this->formFactory = $formFactory; $this->validator = $validator; $this->userContext = $userContext; - $this->localeHelper = $localeHelper; $this->options = $options; $this->translationFactory = new TranslationFactory( @@ -93,6 +86,8 @@ public static function getSubscribedEvents() * Build the custom form based on the provided locales * * @param FormEvent $event + * + * @throws MissingOptionException */ public function preSetData(FormEvent $event) { @@ -139,7 +134,7 @@ public function preSetData(FormEvent $event) $this->getOption('widget'), $accessor->getValue($binded, sprintf('[translation].%s', $this->getOption('field'))), [ - 'label' => $this->localeHelper->getLocaleLabel($binded['locale']), + 'label' => $this->getLocaleLabel($binded['locale']), 'required' => in_array($binded['locale'], $this->getOption('required_locale')), 'mapped' => false, 'auto_initialize' => false @@ -153,6 +148,8 @@ public function preSetData(FormEvent $event) * On submit event (validation) * * @param FormEvent $event + * + * @throws MissingOptionException */ public function submit(FormEvent $event) { @@ -190,6 +187,8 @@ public function submit(FormEvent $event) * On post submit event (after validation) * * @param FormEvent $event + * + * @throws MissingOptionException */ public function postSubmit(FormEvent $event) { @@ -218,6 +217,7 @@ public function postSubmit(FormEvent $event) * @param array $data * * @return mixed string + * @throws MissingOptionException */ protected function bindTranslations($data) { @@ -249,6 +249,7 @@ protected function bindTranslations($data) * Helper method to generate field names in format : '' => '|' * * @return string[] + * @throws MissingOptionException */ protected function getFieldNames() { @@ -281,4 +282,19 @@ protected function getOption($name) return $this->options[$name]; } + + /** + * Returns the label of a locale in the specified language + * + * @param string $code the code of the locale to translate + * @param string $translateIn the locale in which the label should be translated (if null, user locale will be used) + * + * @return string + */ + private function getLocaleLabel($code, $translateIn = null) + { + $translateIn = $translateIn ?: $this->userContext->getCurrentLocaleCode(); + + return \Locale::getDisplayName($code, $translateIn); + } } diff --git a/Form/Type/MediaType.php b/Form/Type/MediaType.php index d7319f2..0f14943 100644 --- a/Form/Type/MediaType.php +++ b/Form/Type/MediaType.php @@ -2,7 +2,7 @@ namespace Kiboko\Bundle\EnrichBundle\Form\Type; -use Akeneo\Bundle\FileStorageBundle\Form\Type\FileInfoType; +use Akeneo\Tool\Bundle\FileStorageBundle\Form\Type\FileInfoType; use Symfony\Component\Form\FormBuilderInterface; class MediaType extends FileInfoType diff --git a/Form/Type/TranslatableType.php b/Form/Type/TranslatableType.php index 393dbf4..aba30c6 100644 --- a/Form/Type/TranslatableType.php +++ b/Form/Type/TranslatableType.php @@ -3,8 +3,7 @@ namespace Kiboko\Bundle\EnrichBundle\Form\Type; use Kiboko\Bundle\EnrichBundle\Form\Subscriber\TranslatableFieldSubscriber; -use Pim\Bundle\CatalogBundle\Helper\LocaleHelper; -use Pim\Bundle\UserBundle\Context\UserContext; +use Akeneo\UserManagement\Bundle\Context\UserContext; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Exception\InvalidConfigurationException; use Symfony\Component\Form\FormBuilderInterface; @@ -23,25 +22,19 @@ class TranslatableType extends AbstractType */ protected $userContext; - /** - * @var LocaleHelper - */ - protected $localeHelper; - /** * @param ValidatorInterface $validator - * @param UserContext $userContext - * @param LocaleHelper $localeHelper + * @param UserContext $userContext */ - public function __construct(ValidatorInterface $validator, UserContext $userContext, LocaleHelper $localeHelper) + public function __construct(ValidatorInterface $validator, UserContext $userContext) { $this->validator = $validator; $this->userContext = $userContext; - $this->localeHelper = $localeHelper; } /** * {@inheritdoc} + * @throws \Akeneo\Platform\Bundle\UIBundle\Exception\MissingOptionException */ public function buildForm(FormBuilderInterface $builder, array $options) { @@ -66,7 +59,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->getFormFactory(), $this->validator, $this->userContext, - $this->localeHelper, $options ); $builder->addEventSubscriber($subscriber); @@ -95,7 +87,7 @@ public function configureOptions(OptionsResolver $resolver) 'locales' => $this->userContext->getUserLocaleCodes(), 'user_locale' => $this->userContext->getUiLocale(), 'required_locale' => [], - 'widget' => 'text' + 'widget' => 'text', ] ); } diff --git a/Model/CustomEntityTrait.php b/Model/CustomEntityTrait.php index c484117..9c2d35d 100644 --- a/Model/CustomEntityTrait.php +++ b/Model/CustomEntityTrait.php @@ -39,7 +39,7 @@ public function getUpdated(): ?\DateTimeInterface /** * @param \DateTimeInterface $created * - * @return AbstractCustomEntity + * @return CustomEntityTrait */ public function setCreated(\DateTimeInterface $created) { @@ -51,7 +51,7 @@ public function setCreated(\DateTimeInterface $created) /** * @param \DateTimeInterface $updated * - * @return AbstractCustomEntity + * @return CustomEntityTrait */ public function setUpdated(\DateTimeInterface $updated) { diff --git a/Model/DescribedInterface.php b/Model/DescribedInterface.php index 381fbc3..355445f 100644 --- a/Model/DescribedInterface.php +++ b/Model/DescribedInterface.php @@ -2,7 +2,7 @@ namespace Kiboko\Bundle\EnrichBundle\Model; -use Akeneo\Component\Localization\Model\TranslatableInterface; +use Akeneo\Tool\Component\Localization\Model\TranslatableInterface; use Doctrine\Common\Collections\Collection; interface DescribedInterface extends TranslatableInterface diff --git a/Model/DescribedTrait.php b/Model/DescribedTrait.php index 66aaabf..6874893 100644 --- a/Model/DescribedTrait.php +++ b/Model/DescribedTrait.php @@ -2,7 +2,7 @@ namespace Kiboko\Bundle\EnrichBundle\Model; -use Akeneo\Component\Localization\Model\TranslationInterface; +use Akeneo\Tool\Component\Localization\Model\TranslationInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; diff --git a/Model/DescribedTranslationInterface.php b/Model/DescribedTranslationInterface.php index db194cb..2bae1f2 100644 --- a/Model/DescribedTranslationInterface.php +++ b/Model/DescribedTranslationInterface.php @@ -2,7 +2,7 @@ namespace Kiboko\Bundle\EnrichBundle\Model; -use Akeneo\Component\Localization\Model\TranslationInterface; +use Akeneo\Tool\Component\Localization\Model\TranslationInterface; interface DescribedTranslationInterface extends TranslationInterface { diff --git a/Model/LabeledInterface.php b/Model/LabeledInterface.php index c029c9a..907a324 100644 --- a/Model/LabeledInterface.php +++ b/Model/LabeledInterface.php @@ -8,7 +8,7 @@ namespace Kiboko\Bundle\EnrichBundle\Model; -use Akeneo\Component\Localization\Model\TranslatableInterface; +use Akeneo\Tool\Component\Localization\Model\TranslatableInterface; use Doctrine\Common\Collections\Collection; interface LabeledInterface extends TranslatableInterface diff --git a/Model/LabeledTrait.php b/Model/LabeledTrait.php index a6b96e8..7e620a9 100644 --- a/Model/LabeledTrait.php +++ b/Model/LabeledTrait.php @@ -2,7 +2,7 @@ namespace Kiboko\Bundle\EnrichBundle\Model; -use Akeneo\Component\Localization\Model\TranslationInterface; +use Akeneo\Tool\Component\Localization\Model\TranslationInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; diff --git a/Model/LabeledTranslationInterface.php b/Model/LabeledTranslationInterface.php index 6ac32f8..bb3071a 100644 --- a/Model/LabeledTranslationInterface.php +++ b/Model/LabeledTranslationInterface.php @@ -2,8 +2,12 @@ namespace Kiboko\Bundle\EnrichBundle\Model; -use Akeneo\Component\Localization\Model\TranslationInterface; +use Akeneo\Tool\Component\Localization\Model\TranslationInterface; +/** + * Interface LabeledTranslationInterface + * @package Kiboko\Bundle\EnrichBundle\Model + */ interface LabeledTranslationInterface extends TranslationInterface { /** diff --git a/Model/PicturedInterface.php b/Model/PicturedInterface.php index 593107a..6b57327 100644 --- a/Model/PicturedInterface.php +++ b/Model/PicturedInterface.php @@ -2,8 +2,8 @@ namespace Kiboko\Bundle\EnrichBundle\Model; -use Akeneo\Component\FileStorage\Model\FileInfoInterface; -use Akeneo\Component\Localization\Model\TranslatableInterface; +use Akeneo\Tool\Component\FileStorage\Model\FileInfoInterface; +use Akeneo\Tool\Component\Localization\Model\TranslatableInterface; use Doctrine\Common\Collections\Collection; interface PicturedInterface extends TranslatableInterface diff --git a/Model/PicturedTrait.php b/Model/PicturedTrait.php index 0828ffa..24531a1 100644 --- a/Model/PicturedTrait.php +++ b/Model/PicturedTrait.php @@ -2,8 +2,8 @@ namespace Kiboko\Bundle\EnrichBundle\Model; -use Akeneo\Component\FileStorage\Model\FileInfoInterface; -use Akeneo\Component\Localization\Model\TranslationInterface; +use Akeneo\Tool\Component\FileStorage\Model\FileInfoInterface; +use Akeneo\Tool\Component\Localization\Model\TranslationInterface; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; diff --git a/Model/PicturedTranslationInterface.php b/Model/PicturedTranslationInterface.php index 41f2349..29216b1 100644 --- a/Model/PicturedTranslationInterface.php +++ b/Model/PicturedTranslationInterface.php @@ -2,9 +2,13 @@ namespace Kiboko\Bundle\EnrichBundle\Model; -use Akeneo\Component\FileStorage\Model\FileInfoInterface; -use Akeneo\Component\Localization\Model\TranslationInterface; +use Akeneo\Tool\Component\FileStorage\Model\FileInfoInterface; +use Akeneo\Tool\Component\Localization\Model\TranslationInterface; +/** + * Interface PicturedTranslationInterface + * @package Kiboko\Bundle\EnrichBundle\Model + */ interface PicturedTranslationInterface extends TranslationInterface { /** diff --git a/Model/PicturedTranslationTrait.php b/Model/PicturedTranslationTrait.php index 4ad06e1..69ff7eb 100644 --- a/Model/PicturedTranslationTrait.php +++ b/Model/PicturedTranslationTrait.php @@ -2,7 +2,7 @@ namespace Kiboko\Bundle\EnrichBundle\Model; -use Akeneo\Component\FileStorage\Model\FileInfoInterface; +use Akeneo\Tool\Component\FileStorage\Model\FileInfoInterface; trait PicturedTranslationTrait { diff --git a/Model/ReferenceDataTrait.php b/Model/ReferenceDataTrait.php index 6f18811..611a1aa 100644 --- a/Model/ReferenceDataTrait.php +++ b/Model/ReferenceDataTrait.php @@ -2,7 +2,6 @@ namespace Kiboko\Bundle\EnrichBundle\Model; -use Symfony\Component\PropertyAccess\PropertyAccessor; use Symfony\Component\PropertyAccess\PropertyAccessorBuilder; trait ReferenceDataTrait diff --git a/Model/TranslatableCustomEntityTrait.php b/Model/TranslatableCustomEntityTrait.php index 8307b81..c7b08f3 100644 --- a/Model/TranslatableCustomEntityTrait.php +++ b/Model/TranslatableCustomEntityTrait.php @@ -2,8 +2,6 @@ namespace Kiboko\Bundle\EnrichBundle\Model; -use Doctrine\Common\Collections\Collection; -use Pim\Bundle\CustomEntityBundle\Entity\TranslatableTrait; use Symfony\Component\PropertyAccess\PropertyAccessorBuilder; trait TranslatableCustomEntityTrait diff --git a/Provider/Field/TranslatableFieldProvider.php b/Provider/Field/TranslatableFieldProvider.php index e138972..5ce699b 100644 --- a/Provider/Field/TranslatableFieldProvider.php +++ b/Provider/Field/TranslatableFieldProvider.php @@ -2,7 +2,7 @@ namespace Kiboko\Bundle\EnrichBundle\Provider\Field; -use Pim\Component\Catalog\Model\AttributeInterface; +use Akeneo\Pim\Structure\Component\Model\AttributeInterface; class TranslatableFieldProvider { diff --git a/Repository/ChoicesRepository.php b/Repository/ChoicesRepository.php index d4137b0..ea39ecc 100644 --- a/Repository/ChoicesRepository.php +++ b/Repository/ChoicesRepository.php @@ -2,10 +2,8 @@ namespace Kiboko\Bundle\EnrichBundle\Repository; -use Kiboko\Bundle\EnrichBundle\Model\MappedOption; use Doctrine\ORM\EntityManager; - class ChoicesRepository { /** @@ -38,7 +36,6 @@ public function getChoices() $values = $entityRepository->findAll(); $choices = []; - /** @var MappedOption $value */ foreach ($values as $value) { $choices[$value->getId()] = $value->getLabel(); } diff --git a/Resources/config/form_types.yml b/Resources/config/form_types.yml index 644362c..c318b44 100644 --- a/Resources/config/form_types.yml +++ b/Resources/config/form_types.yml @@ -8,13 +8,12 @@ services: arguments: - '@validator' - '@pim_user.context.user' - - '@pim_catalog.helper.locale' tags: - { name: form.type, alias: kiboko_translatable_field } kiboko_enrich.form.type.media_field: class: '%kiboko_enrich.form.type.media_field.class%' arguments: - - %akeneo_file_storage.model.file_info.class% + - '%akeneo_file_storage.model.file_info.class%' tags: - { name: form.type, alias: kiboko_enrich_media } diff --git a/Utils/FileInfoUtils.php b/Utils/FileInfoUtils.php index aa650ac..c1dbc83 100644 --- a/Utils/FileInfoUtils.php +++ b/Utils/FileInfoUtils.php @@ -2,9 +2,9 @@ namespace Kiboko\Bundle\EnrichBundle\Utils; -use Akeneo\Component\FileStorage\FileInfoFactoryInterface; -use Akeneo\Component\FileStorage\Model\FileInfoInterface; -use Pim\Component\Catalog\FileStorage; +use Akeneo\Pim\Enrichment\Component\FileStorage; +use Akeneo\Tool\Component\FileStorage\FileInfoFactoryInterface; +use Akeneo\Tool\Component\FileStorage\Model\FileInfoInterface; use Symfony\Component\HttpFoundation\File\UploadedFile; /** diff --git a/composer.json b/composer.json index 5a050a1..2d09ec1 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "akeneo-labs/custom-entity-bundle": "~2.1|~2.2|~2.4|~3.0" + "akeneo-labs/custom-entity-bundle": "~3.0" }, "autoload": { "psr-4": { @@ -29,7 +29,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0.x-dev" } } }