Skip to content
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

3.0.0 #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions EventListener/FilePersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +21,8 @@ public function __construct(Filesystem $filesystem)

/**
* @param GenericEvent $event
*
* @throws \League\Flysystem\FileExistsException
*/
public function onAkeneoStoragePostsave(GenericEvent $event)
{
Expand Down Expand Up @@ -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)
{
Expand Down
13 changes: 6 additions & 7 deletions Form/EventListener/PicturedFormListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@

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;

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;
}
Expand All @@ -34,7 +33,7 @@ public function __construct(FileInfo $utils)
public static function getSubscribedEvents()
{
return [
FormEvents::POST_SUBMIT => 'postSubmit'
FormEvents::POST_SUBMIT => 'postSubmit',
];
}

Expand Down
48 changes: 32 additions & 16 deletions Form/Subscriber/TranslatableFieldSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,11 +36,6 @@ class TranslatableFieldSubscriber implements EventSubscriberInterface
*/
protected $options;

/**
* @var LocaleHelper
*/
protected $localeHelper;

/**
* @var UserContext
*/
Expand All @@ -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(
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand All @@ -153,6 +148,8 @@ public function preSetData(FormEvent $event)
* On submit event (validation)
*
* @param FormEvent $event
*
* @throws MissingOptionException
*/
public function submit(FormEvent $event)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -218,6 +217,7 @@ public function postSubmit(FormEvent $event)
* @param array $data
*
* @return mixed string
* @throws MissingOptionException
*/
protected function bindTranslations($data)
{
Expand Down Expand Up @@ -249,6 +249,7 @@ protected function bindTranslations($data)
* Helper method to generate field names in format : '<locale>' => '<field>|<locale>'
*
* @return string[]
* @throws MissingOptionException
*/
protected function getFieldNames()
{
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion Form/Type/MediaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 5 additions & 13 deletions Form/Type/TranslatableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -66,7 +59,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->getFormFactory(),
$this->validator,
$this->userContext,
$this->localeHelper,
$options
);
$builder->addEventSubscriber($subscriber);
Expand Down Expand Up @@ -95,7 +87,7 @@ public function configureOptions(OptionsResolver $resolver)
'locales' => $this->userContext->getUserLocaleCodes(),
'user_locale' => $this->userContext->getUiLocale(),
'required_locale' => [],
'widget' => 'text'
'widget' => 'text',
]
);
}
Expand Down
4 changes: 2 additions & 2 deletions Model/CustomEntityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getUpdated(): ?\DateTimeInterface
/**
* @param \DateTimeInterface $created
*
* @return AbstractCustomEntity
* @return CustomEntityTrait
*/
public function setCreated(\DateTimeInterface $created)
{
Expand All @@ -51,7 +51,7 @@ public function setCreated(\DateTimeInterface $created)
/**
* @param \DateTimeInterface $updated
*
* @return AbstractCustomEntity
* @return CustomEntityTrait
*/
public function setUpdated(\DateTimeInterface $updated)
{
Expand Down
2 changes: 1 addition & 1 deletion Model/DescribedInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Model/DescribedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Model/DescribedTranslationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion Model/LabeledInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Model/LabeledTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 5 additions & 1 deletion Model/LabeledTranslationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down
4 changes: 2 additions & 2 deletions Model/PicturedInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Model/PicturedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 6 additions & 2 deletions Model/PicturedTranslationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
Expand Down
2 changes: 1 addition & 1 deletion Model/PicturedTranslationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Kiboko\Bundle\EnrichBundle\Model;

use Akeneo\Component\FileStorage\Model\FileInfoInterface;
use Akeneo\Tool\Component\FileStorage\Model\FileInfoInterface;

trait PicturedTranslationTrait
{
Expand Down
1 change: 0 additions & 1 deletion Model/ReferenceDataTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Kiboko\Bundle\EnrichBundle\Model;

use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\PropertyAccess\PropertyAccessorBuilder;

trait ReferenceDataTrait
Expand Down
Loading