-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
95 additions
and
101 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
10 changes: 8 additions & 2 deletions
10
src/ObjectInfo/DoctrineInfo.php → ...tractor/DoctrineEntityFieldsExtractor.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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
<?php | ||
|
||
namespace Koff\Bundle\I18nFormBundle\ObjectInfo; | ||
namespace Koff\Bundle\I18nFormBundle\Extractor; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\Mapping\ClassMetadata; | ||
use Koff\Bundle\I18nFormBundle\Form\Type\AutoFormType; | ||
|
||
class DoctrineInfo implements ObjectInfoInterface | ||
/** | ||
* Class DoctrineEntityFieldsExtractor. | ||
* | ||
* @author David ALLIX | ||
* @author Sadicov Vladimir <[email protected]> | ||
*/ | ||
class DoctrineEntityFieldsExtractor implements FieldsExtractorInterface | ||
{ | ||
/** @var EntityManagerInterface */ | ||
private $entityManager; | ||
|
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,15 @@ | ||
<?php | ||
|
||
namespace Koff\Bundle\I18nFormBundle\Extractor; | ||
|
||
/** | ||
* Interface EntityInfoInterface. | ||
* | ||
* @author Sadicov Vladimir <[email protected]> | ||
*/ | ||
interface FieldsExtractorInterface | ||
{ | ||
public function getFieldsConfig($class); | ||
|
||
public function getAssociationTargetClass($class, $fieldName); | ||
} |
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 |
---|---|---|
|
@@ -6,6 +6,11 @@ | |
use Symfony\Component\Form\FormEvent; | ||
use Symfony\Component\Form\FormEvents; | ||
|
||
/** | ||
* Class KoffI18nListener. | ||
* | ||
* @author Sadicov Vladimir <[email protected]> | ||
*/ | ||
abstract class KoffI18nListener implements EventSubscriberInterface | ||
{ | ||
/** | ||
|
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 |
---|---|---|
|
@@ -12,21 +12,15 @@ | |
namespace Koff\Bundle\I18nFormBundle\Form\EventListener; | ||
|
||
use Symfony\Component\Form\FormEvent; | ||
use Symfony\Component\Form\FormEvents; | ||
|
||
/** | ||
* Class TranslationsFormsListener. | ||
* | ||
* @author David ALLIX | ||
* @author Sadicov Vladimir <[email protected]> | ||
*/ | ||
class TranslationsFormsListener extends KoffI18nListener | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
FormEvents::PRE_SET_DATA => 'preSetData', | ||
FormEvents::SUBMIT => 'submit', | ||
]; | ||
} | ||
|
||
/** | ||
* @param FormEvent $event | ||
*/ | ||
|
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 |
---|---|---|
@@ -1,22 +1,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of A2lix projects. | ||
* | ||
* (c) David ALLIX | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Koff\Bundle\I18nFormBundle\Form\EventListener; | ||
|
||
use Koff\Bundle\I18nFormBundle\Form\Manipulator\FormManipulatorInterface; | ||
use Koff\Bundle\I18nFormBundle\Form\Type\AutoFormType; | ||
use Symfony\Component\Form\FormEvent; | ||
use Symfony\Component\Form\FormEvents; | ||
use Symfony\Component\Form\FormInterface; | ||
|
||
/** | ||
* Class TranslationsListener. | ||
* | ||
* @author David ALLIX | ||
* @author Sadicov Vladimir <[email protected]> | ||
*/ | ||
class TranslationsListener extends KoffI18nListener | ||
{ | ||
/** @var FormManipulatorInterface */ | ||
|
@@ -30,17 +26,6 @@ public function __construct(FormManipulatorInterface $formManipulator) | |
$this->formManipulator = $formManipulator; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
FormEvents::PRE_SET_DATA => 'preSetData', | ||
FormEvents::SUBMIT => 'submit', | ||
]; | ||
} | ||
|
||
/** | ||
* @param FormEvent $event | ||
*/ | ||
|
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
namespace Koff\Bundle\I18nFormBundle\Form\Manipulator; | ||
|
||
use Doctrine\Common\Util\ClassUtils; | ||
use Koff\Bundle\I18nFormBundle\ObjectInfo\ObjectInfoInterface; | ||
use Koff\Bundle\I18nFormBundle\Extractor\FieldsExtractorInterface; | ||
use Symfony\Component\Form\FormInterface; | ||
|
||
/** | ||
|
@@ -12,21 +12,21 @@ | |
* @author David ALLIX | ||
* @author Sadicov Vladimir <[email protected]> | ||
*/ | ||
class DefaultManipulator implements FormManipulatorInterface | ||
class FormManipulator implements FormManipulatorInterface | ||
{ | ||
/** @var ObjectInfoInterface */ | ||
private $objectInfo; | ||
/** @var FieldsExtractorInterface */ | ||
private $fieldsExtractor; | ||
|
||
/** @var array */ | ||
private $globalExcludedFields; | ||
|
||
/** | ||
* @param ObjectInfoInterface $objectInfo | ||
* @param array $globalExcludedFields | ||
* @param FieldsExtractorInterface $fieldsExtractor | ||
* @param array $globalExcludedFields | ||
*/ | ||
public function __construct(ObjectInfoInterface $objectInfo, array $globalExcludedFields = []) | ||
public function __construct(FieldsExtractorInterface $fieldsExtractor, array $globalExcludedFields = []) | ||
{ | ||
$this->objectInfo = $objectInfo; | ||
$this->fieldsExtractor = $fieldsExtractor; | ||
$this->globalExcludedFields = $globalExcludedFields; | ||
} | ||
|
||
|
@@ -39,7 +39,7 @@ public function getFieldsConfig(FormInterface $form) | |
$formOptions = $form->getConfig()->getOptions(); | ||
$formFields = $formOptions['fields']; | ||
|
||
$objectFields = $this->objectInfo->getFieldsConfig($class); | ||
$objectFields = $this->fieldsExtractor->getFieldsConfig($class); | ||
$objectFields = $this->filterObjectFields($objectFields, $formOptions['excluded_fields']); | ||
|
||
if (empty($formFields)) { | ||
|
@@ -49,9 +49,13 @@ public function getFieldsConfig(FormInterface $form) | |
$this->checkUnknownFields($formFields, $objectFields, $class); | ||
|
||
$fieldsConfig = $this->filterFields($formFields); | ||
array_walk($fieldsConfig, function (&$v, $k, $d) { | ||
$v += $d[$k]; | ||
}, $objectFields); | ||
array_walk( | ||
$fieldsConfig, | ||
function (&$v, $k, $d) { | ||
$v += $d[$k]; | ||
}, | ||
$objectFields | ||
); | ||
|
||
return $fieldsConfig; | ||
} | ||
|
@@ -93,7 +97,7 @@ private function getDataClass(FormInterface $form) | |
continue; | ||
} | ||
|
||
return $this->objectInfo->getAssociationTargetClass($dataClass, $form->getName()); | ||
return $this->fieldsExtractor->getAssociationTargetClass($dataClass, $form->getName()); | ||
} | ||
} | ||
|
||
|
@@ -112,8 +116,11 @@ private function filterObjectFields(array $objectFieldsConfig, array $formExclud | |
|
||
private function filterFields($fields) | ||
{ | ||
return array_filter($fields, function ($v) { | ||
return !(null === $v || (array_key_exists('display', $v) && !$v['display'])); | ||
}); | ||
return array_filter( | ||
$fields, | ||
function ($v) { | ||
return !(null === $v || (array_key_exists('display', $v) && !$v['display'])); | ||
} | ||
); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,17 +1,13 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of A2lix projects. | ||
* | ||
* (c) Gonzalo Vilaseca <[email protected]> . Reiss Clothing Ltd. | ||
namespace Koff\Bundle\I18nFormBundle\Provider; | ||
|
||
/** | ||
* Class LocaleProvider. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* @author Gonzalo Vilaseca <[email protected]> . Reiss Clothing Ltd. | ||
*/ | ||
|
||
namespace Koff\Bundle\I18nFormBundle\Locale; | ||
|
||
class DefaultProvider implements LocaleProviderInterface | ||
class LocaleProvider implements LocaleProviderInterface | ||
{ | ||
/** @var array */ | ||
protected $locales; | ||
|
@@ -31,10 +27,10 @@ public function __construct(array $locales, $defaultLocale, array $requiredLocal | |
{ | ||
if (!in_array($defaultLocale, $locales, true)) { | ||
if (count($locales)) { | ||
throw new \InvalidArgumentException(sprintf('Default locale `%s` not found within the configured locales `[%s]`. Perhaps you need to add it to your `koff_i18n_form.locales` bundle configuration?', $defaultLocale, implode(',', $locales))); | ||
throw new \InvalidArgumentException(sprintf('Default locale `%s` not found within the configured locales `[%s]`. Perhaps you need to add it to your `i18n_form.locales` bundle configuration?', $defaultLocale, implode(',', $locales))); | ||
} | ||
|
||
throw new \InvalidArgumentException(sprintf('No locales were configured, but expected at least the default locale `%s`. Perhaps you need to add it to your `koff_i18n_form.locales` bundle configuration?', $defaultLocale)); | ||
throw new \InvalidArgumentException(sprintf('No locales were configured, but expected at least the default locale `%s`. Perhaps you need to add it to your `i18n_form.locales` bundle configuration?', $defaultLocale)); | ||
} | ||
|
||
if (array_diff($requiredLocales, $locales)) { | ||
|
14 changes: 5 additions & 9 deletions
14
src/Locale/LocaleProviderInterface.php → src/Provider/LocaleProviderInterface.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 |
---|---|---|
@@ -1,16 +1,12 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of A2lix projects. | ||
* | ||
* (c) Gonzalo Vilaseca <[email protected]> . Reiss Clothing Ltd. | ||
namespace Koff\Bundle\I18nFormBundle\Provider; | ||
|
||
/** | ||
* Interface LocaleProviderInterface. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* @author Gonzalo Vilaseca <[email protected]> . Reiss Clothing Ltd. | ||
*/ | ||
|
||
namespace Koff\Bundle\I18nFormBundle\Locale; | ||
|
||
interface LocaleProviderInterface | ||
{ | ||
/** | ||
|
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
Oops, something went wrong.