diff --git a/.travis.yml b/.travis.yml index 75e5d68..369e3ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,12 +9,15 @@ sudo: required addons: firefox: "47.0.1" +services: + - xvfb + matrix: include: - php: 7.1 env: - COMPOSER_FLAGS='--prefer-lowest' - - php: 7.2 + - php: 7.3 before_install: - phpenv config-rm xdebug.ini @@ -26,8 +29,6 @@ before_script: - nohup php -S localhost:8080 -t features/fixtures/project/web > server.log 2>&1 & - features/fixtures/project/app/console ckeditor:install --clear=skip - features/fixtures/project/app/console assets:install --symlink features/fixtures/project/web - - sh -e /etc/init.d/xvfb start - - export DISPLAY=:99.0 - java -jar vendor/bin/selenium.jar > /dev/null 2>&1 & - sleep 5 diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 726ae5d..1358979 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -28,8 +28,14 @@ public function __construct(array $adminTemplates) public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('fsi_admin_translatable'); + if (true === method_exists(TreeBuilder::class, 'getRootNode')) { + $treeBuilder = new TreeBuilder('fsi_admin_translatable'); + $rootNode = $treeBuilder->getRootNode(); + } else { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('fsi_admin_translatable'); + } + $rootNode ->children() ->arrayNode('locales') diff --git a/DependencyInjection/FSIAdminTranslatableExtension.php b/DependencyInjection/FSIAdminTranslatableExtension.php index 2c3433d..1aa9166 100644 --- a/DependencyInjection/FSIAdminTranslatableExtension.php +++ b/DependencyInjection/FSIAdminTranslatableExtension.php @@ -11,12 +11,11 @@ namespace FSi\Bundle\AdminTranslatableBundle\DependencyInjection; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; class FSIAdminTranslatableExtension extends Extension implements PrependExtensionInterface { @@ -41,10 +40,7 @@ public function load(array $configs, ContainerBuilder $container) ); $loader->load('services.xml'); $loader->load('controller.xml'); - $loader->load(TypeSolver::isSymfony3FormNamingConvention() - ? 'form-symfony-3.xml' - : 'form-symfony-2.xml' - ); + $loader->load('form.xml'); $loader->load('datagrid.xml'); $loader->load('menu.xml'); diff --git a/Form/AbstractTranslatableExtension.php b/Form/AbstractTranslatableExtension.php index 8a71677..33dd4b2 100644 --- a/Form/AbstractTranslatableExtension.php +++ b/Form/AbstractTranslatableExtension.php @@ -22,17 +22,11 @@ abstract class AbstractTranslatableExtension extends AbstractTypeExtension */ protected $translatableFormHelper; - /** - * @param TranslatableFormHelper $translatableFormHelper - */ public function __construct(TranslatableFormHelper $translatableFormHelper) { $this->translatableFormHelper = $translatableFormHelper; } - /** - * {@inheritdoc} - */ public function finishView(FormView $view, FormInterface $form, array $options) { $view->vars['translatable'] = false; diff --git a/Form/LocaleExtension.php b/Form/LocaleExtension.php index 23742fb..0385ddb 100644 --- a/Form/LocaleExtension.php +++ b/Form/LocaleExtension.php @@ -12,7 +12,6 @@ namespace FSi\Bundle\AdminTranslatableBundle\Form; use Doctrine\Common\Persistence\ObjectManager; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; use FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata; use FSi\DoctrineExtensions\Translatable\TranslatableListener; use Symfony\Bridge\Doctrine\ManagerRegistry; @@ -58,9 +57,14 @@ public static function getSubscribedEvents() ]; } + public static function getExtendedTypes() + { + return [FormType::class]; + } + public function getExtendedType() { - return TypeSolver::getFormType(FormType::class, 'form'); + return FormType::class; } public function buildForm(FormBuilderInterface $formBuilder, array $options) diff --git a/Form/TranslatableCollectionExtension.php b/Form/TranslatableCollectionExtension.php index b86de08..29b2516 100644 --- a/Form/TranslatableCollectionExtension.php +++ b/Form/TranslatableCollectionExtension.php @@ -11,7 +11,7 @@ namespace FSi\Bundle\AdminTranslatableBundle\Form; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; +use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\FormBuilderInterface; class TranslatableCollectionExtension extends AbstractSimpleTranslatableExtension @@ -29,20 +29,16 @@ public function __construct( $this->listener = $listener; } - /** - * @inheritdoc - */ + public static function getExtendedTypes() + { + return [CollectionType::class]; + } + public function getExtendedType() { - return TypeSolver::getFormType( - 'Symfony\Component\Form\Extension\Core\Type\CollectionType', - 'collection' - ); + return CollectionType::class; } - /** - * @inheritdoc - */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventSubscriber($this->listener); diff --git a/Form/TranslatableCollectionListener.php b/Form/TranslatableCollectionListener.php index d48b5c2..ead3001 100644 --- a/Form/TranslatableCollectionListener.php +++ b/Form/TranslatableCollectionListener.php @@ -40,7 +40,8 @@ public function onPreSetData(FormEvent $event) $parent = $this->translatableFormHelper->getFirstTranslatableParent($form); if ($this->translatableFormHelper->isFormPropertyPathTranslatable($form) - && !$this->translatableFormHelper->isFormDataInCurrentLocale($parent)) { + && !$this->translatableFormHelper->isFormDataInCurrentLocale($parent) + ) { $event->setData(null); } } diff --git a/Form/TranslatableFSiRemovableFileExtension.php b/Form/TranslatableFSiRemovableFileExtension.php index 3df207c..971db38 100644 --- a/Form/TranslatableFSiRemovableFileExtension.php +++ b/Form/TranslatableFSiRemovableFileExtension.php @@ -11,7 +11,6 @@ namespace FSi\Bundle\AdminTranslatableBundle\Form; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; use FSi\Bundle\DoctrineExtensionsBundle\Form\Type\FSi\RemovableFileType; use FSi\Bundle\DoctrineExtensionsBundle\Resolver\FSiFilePathResolver; use Symfony\Component\Form\FormInterface; @@ -32,33 +31,21 @@ public function __construct( $this->filePathResolver = $filePathResolver; } - /** - * @inheritdoc - */ + public static function getExtendedTypes() + { + return [RemovableFileType::class]; + } + public function getExtendedType() { - return TypeSolver::getFormType( - RemovableFileType::class, - 'fsi_removable_file' - ); + return RemovableFileType::class; } - /** - * @param FormView $view - * @param FormInterface $form - * @param array $options - * @return bool - */ protected function hasCurrentValue(FormView $view, FormInterface $form, array $options): bool { return isset($view[$form->getName()]->vars['data']); } - /** - * @param FormView $view - * @param FormInterface $form - * @param array $options - */ protected function moveCurrentValueToDefaultLocaleValue( FormView $view, FormInterface $form, diff --git a/Form/TranslatableTextExtension.php b/Form/TranslatableTextExtension.php index 5d729c7..8d8c238 100644 --- a/Form/TranslatableTextExtension.php +++ b/Form/TranslatableTextExtension.php @@ -11,15 +11,17 @@ namespace FSi\Bundle\AdminTranslatableBundle\Form; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; +use Symfony\Component\Form\Extension\Core\Type\TextType; class TranslatableTextExtension extends AbstractSimpleTranslatableExtension { - /** - * @inheritdoc - */ + public static function getExtendedTypes() + { + return [TextType::class]; + } + public function getExtendedType() { - return TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\TextType', 'text'); + return TextType::class; } } diff --git a/Form/TypeSolver.php b/Form/TypeSolver.php deleted file mode 100644 index 772b52f..0000000 --- a/Form/TypeSolver.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -declare(strict_types=1); - -namespace FSi\Bundle\AdminTranslatableBundle\Form; - -use Symfony\Component\Form\FormTypeInterface; - -/** - * @internal - */ -final class TypeSolver -{ - /** - * Return FQCN form type or old style form type - * - * @param string $fqcnType - * @param string|FormTypeInterface $shortType - * @return string|FormTypeInterface - */ - public static function getFormType(string $fqcnType, $shortType) - { - return self::isSymfony3FormNamingConvention() ? $fqcnType : $shortType; - } - - /** - * @return bool - */ - public static function isSymfony3FormNamingConvention(): bool - { - return !method_exists(FormTypeInterface::class, 'getName'); - } -} diff --git a/Resources/config/form-symfony-2.xml b/Resources/config/form-symfony-2.xml deleted file mode 100644 index e1e2750..0000000 --- a/Resources/config/form-symfony-2.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - FSi\Bundle\AdminTranslatableBundle\EventListener\LocaleListener - FSi\Bundle\AdminTranslatableBundle\Form\LocaleExtension - FSi\Bundle\AdminTranslatableBundle\Form\TranslatableTextExtension - FSi\Bundle\AdminTranslatableBundle\Form\TranslatableCollectionExtension - FSi\Bundle\AdminTranslatableBundle\Form\TranslatableCollectionListener - FSi\Bundle\AdminTranslatableBundle\Form\TranslatableFormHelper - FSi\Bundle\AdminTranslatableBundle\Form\TranslatableFSiRemovableFileExtension - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Resources/config/form-symfony-3.xml b/Resources/config/form.xml similarity index 100% rename from Resources/config/form-symfony-3.xml rename to Resources/config/form.xml diff --git a/composer.json b/composer.json index 80e6d02..59be2f6 100644 --- a/composer.json +++ b/composer.json @@ -11,18 +11,18 @@ } ], "require": { - "fsi/admin-bundle": "^3.0", + "fsi/admin-bundle": "^3.1", "fsi/doctrine-extensions-bundle": "^2.0", "php": ">=7.1", - "symfony/form": "^2.8|^3.0|^4.0", - "symfony/framework-bundle": "^2.8|^3.0|^4.0", - "symfony/http-kernel": "^2.8|^3.0|^4.0", - "symfony/options-resolver": "^2.6|^3.0|^4.0", - "symfony/routing": "^2.4|^3.0|^4.0", - "symfony/translation": "^2.6|^3.0|^4.0", - "symfony/twig-bridge": "^3.0.3|^4.0", - "symfony/validator": "^2.5|^3.0|^4.0", - "symfony/twig-bundle": "^2.8|^3.0|^4.0" + "symfony/form": "^3.4|^4.0", + "symfony/framework-bundle": "^3.4|^4.0", + "symfony/http-kernel": "^3.4|^4.0", + "symfony/options-resolver": "^3.4|^4.0", + "symfony/routing": "^3.4|^4.0", + "symfony/translation": "^3.4|^4.0", + "symfony/twig-bridge": "^3.4|^4.0", + "symfony/validator": "^3.4|^4.0", + "symfony/twig-bundle": "^3.4|^4.0" }, "require-dev": { "behat/behat": "^3.3", @@ -31,21 +31,24 @@ "behat/mink-extension": "^2.2", "behat/mink-selenium2-driver": "^1.3", "behat/symfony2-extension": "^2.1", - "bossa/phpspec2-expect": "^2.0|^3.0", + "bossa/phpspec2-expect": "^3.0", "doctrine/doctrine-bundle": "^1.6", "ext-pdo_sqlite": "*", "friendsofsymfony/ckeditor-bundle": "^1.0", + "fsi/datagrid": "^2.0", + "fsi/datasource": "^2.0", "fsi/resource-repository-bundle": "^2.0", - "phpspec/phpspec": "^3.4.2|^4.0", - "phpspec/prophecy": "^1.7.2", + "phpspec/phpspec": "^5.0", + "phpspec/prophecy": "^1.7", "sensiolabs/behat-page-object-extension": "^3.0@dev", - "symfony/browser-kit": "^2.8|^3.0|^4.0", - "symfony/console": "^2.8|^3.0|^4.0", - "symfony/css-selector": "^2.8|^3.0|^4.0", - "symfony/debug": "^2.8|^3.0|^4.0", - "symfony/dom-crawler": "^2.8|^3.0|^4.0", - "symfony/var-dumper": "^2.8|^3.0|^4.0", - "twig/twig": "^1.34|^2.0" + "symfony/browser-kit": "^3.4|^4.0", + "symfony/console": "^3.4|^4.0", + "symfony/css-selector": "^3.4|^4.0", + "symfony/debug": "^3.4|^4.0", + "symfony/dom-crawler": "^3.4|^4.0", + "symfony/var-dumper": "^3.4|^4.0", + "twig/twig": "^2.0", + "symfony/phpunit-bridge": "^4.3" }, "config": { "bin-dir": "vendor/bin" @@ -63,7 +66,8 @@ }, "extra": { "branch-alias": { - "dev-master": "3.0-dev", + "dev-master": "3.1-dev", + "3.0": "3.0-dev", "2.1": "2.1-dev", "2.0": "2.0-dev" } diff --git a/features/fixtures/project/app/config/config.yml b/features/fixtures/project/app/config/config.yml index e4c650a..da11785 100644 --- a/features/fixtures/project/app/config/config.yml +++ b/features/fixtures/project/app/config/config.yml @@ -1,7 +1,17 @@ parameters: locale: en + locales: [pl,en,de] services: + _defaults: + autowire: true + autoconfigure: true + public: false + + FSi\FixturesBundle\: + resource: '../../src/FSi/FixturesBundle/*' + exclude: '../../src/FSi/FixturesBundle/{Entity,FSiFixturesBundle.php}' + test.admin.manager: alias: admin.manager public: true @@ -44,14 +54,8 @@ fsi_resource_repository: resource_class: FSi\FixturesBundle\Entity\Resource fsi_admin_translatable: - locales: - - pl - - en - - de + locales: '%locales%' fsi_admin: default_locale: "%locale%" - locales: - - pl - - en - - de + locales: '%locales%' diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Admin/CommentList.php b/features/fixtures/project/src/FSi/FixturesBundle/Admin/CommentList.php index a8205a7..6751206 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Admin/CommentList.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Admin/CommentList.php @@ -1,17 +1,23 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Admin; -use FSi\Bundle\AdminBundle\Annotation as Admin; use FSi\Bundle\AdminTranslatableBundle\Doctrine\Admin\TranslatableListElement; use FSi\Component\DataGrid\DataGridFactoryInterface; use FSi\Component\DataGrid\DataGridInterface; use FSi\Component\DataSource\DataSourceFactoryInterface; use FSi\Component\DataSource\DataSourceInterface; +use FSi\FixturesBundle\Entity\Comment; -/** - * @Admin\Element - */ class CommentList extends TranslatableListElement { public function getId(): string @@ -21,7 +27,7 @@ public function getId(): string public function getClassName(): string { - return 'FSi\FixturesBundle\Entity\Comment'; + return Comment::class; } protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInterface diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Admin/Event.php b/features/fixtures/project/src/FSi/FixturesBundle/Admin/Event.php index 1eef050..b3db187 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Admin/Event.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Admin/Event.php @@ -1,10 +1,20 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Admin; +use FOS\CKEditorBundle\Form\Type\CKEditorType; use FSi\Bundle\AdminBundle\Annotation as Admin; use FSi\Bundle\AdminTranslatableBundle\Doctrine\Admin\TranslatableCRUDElement; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; +use FSi\Bundle\DoctrineExtensionsBundle\Form\Type\FSi\RemovableFileType; use FSi\Component\DataGrid\DataGridFactoryInterface; use FSi\Component\DataGrid\DataGridInterface; use FSi\Component\DataSource\DataSourceFactoryInterface; @@ -12,6 +22,9 @@ use FSi\FixturesBundle\Entity\Event as EventEntity; use FSi\FixturesBundle\Form\CommentType; use FSi\FixturesBundle\Form\FilesType; +use Symfony\Component\Form\Extension\Core\Type\CollectionType; +use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; @@ -20,25 +33,16 @@ */ class Event extends TranslatableCRUDElement { - /** - * {@inheritDoc} - */ public function getId(): string { return 'admin_event'; } - /** - * {@inheritDoc} - */ public function getClassName(): string { - return 'FSi\FixturesBundle\Entity\Event'; + return EventEntity::class; } - /** - * {@inheritDoc} - */ protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInterface { $datagrid = $factory->createDataGrid($this->getId()); @@ -72,59 +76,30 @@ protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInte return $datagrid; } - /** - * {@inheritDoc} - */ protected function initDataSource(DataSourceFactoryInterface $factory): DataSourceInterface { $qb = $this->getRepository()->createTranslatableQueryBuilder('e', 't', 'dt'); $datasource = $factory->createDataSource('doctrine-orm', ['qb' => $qb], $this->getId()); - - $datasource->addField('name', 'text', 'like', [ - 'field' => 't.name' - ]); + $datasource->addField('name', 'text', 'like', ['field' => 't.name']); return $datasource; } - /** - * {@inheritDoc} - */ protected function initForm(FormFactoryInterface $factory, $data = null): FormInterface { - if (!$data) { - $data = new EventEntity(); - } - $formType = TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\FormType', 'form'); - $textType = TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\TextType', 'text'); - $ckeditorType = TypeSolver::getFormType('FOS\CKEditorBundle\Form\Type\CKEditorType', 'ckeditor'); - $collectionType = TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\CollectionType', 'collection'); - $removableFileType = TypeSolver::getFormType( - 'FSi\Bundle\DoctrineExtensionsBundle\Form\Type\FSi\RemovableFileType', - 'fsi_removable_file' - ); - $commentType = TypeSolver::getFormType('FSi\FixturesBundle\Form\CommentType', new CommentType()); - $filesType = TypeSolver::getFormType('FSi\FixturesBundle\Form\FilesType', new FilesType()); - - $form = $factory->create($formType, $data, ['data_class' => $this->getClassName()]); - - $form->add('name', $textType, ['label' => 'admin.events.form.name']); - - $form->add('agreement', $removableFileType, ['required' => false]); - - $form->add('description', $ckeditorType, ['required' => false]); - - $entryTypeLabel = TypeSolver::isSymfony3FormNamingConvention()? 'entry_type' : 'type'; - $form->add('comments', $collectionType, [ - $entryTypeLabel => $commentType, + $form = $factory->create(FormType::class, $data ?? new EventEntity(), ['data_class' => $this->getClassName()]); + $form->add('name', TextType::class, ['label' => 'admin.events.form.name']); + $form->add('agreement', RemovableFileType::class, ['required' => false]); + $form->add('description', CKEditorType::class, ['required' => false]); + $form->add('comments', CollectionType::class, [ + 'entry_type' => CommentType::class, 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false ]); - - $form->add('files', $collectionType, [ - $entryTypeLabel => $filesType, + $form->add('files', CollectionType::class, [ + 'entry_type' => FilesType::class, 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Admin/EventPreview.php b/features/fixtures/project/src/FSi/FixturesBundle/Admin/EventPreview.php index 058eb94..37c8761 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Admin/EventPreview.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Admin/EventPreview.php @@ -1,15 +1,21 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Admin; -use FSi\Bundle\AdminBundle\Annotation as Admin; use FSi\Bundle\AdminBundle\Display\Display; use FSi\Bundle\AdminBundle\Display\PropertyAccessDisplay; use FSi\Bundle\AdminTranslatableBundle\Doctrine\Admin\TranslatableDisplayElement; +use FSi\FixturesBundle\Entity\Event; -/** - * @Admin\Element - */ class EventPreview extends TranslatableDisplayElement { public function getId(): string @@ -19,7 +25,7 @@ public function getId(): string public function getClassName(): string { - return 'FSi\FixturesBundle\Entity\Event'; + return Event::class; } protected function initDisplay($object): Display diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Admin/Form.php b/features/fixtures/project/src/FSi/FixturesBundle/Admin/Form.php index 53390ac..5d7b935 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Admin/Form.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Admin/Form.php @@ -1,16 +1,23 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Admin; -use FSi\Bundle\AdminBundle\Annotation as Admin; use FSi\Bundle\AdminTranslatableBundle\Doctrine\Admin\TranslatableFormElement; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; +use FSi\FixturesBundle\Entity\Comment; +use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; -/** - * @Admin\Element - */ class Form extends TranslatableFormElement { public function getId(): string @@ -20,16 +27,13 @@ public function getId(): string public function getClassName(): string { - return 'FSi\FixturesBundle\Entity\Comment'; + return Comment::class; } protected function initForm(FormFactoryInterface $factory, $data = null): FormInterface { - $formType = TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\FormType', 'form'); - $textareaType = TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\TextareaType', 'textarea'); - - $form = $factory->create($formType, $data, ['data_class' => $this->getClassName()]); - $form->add('text', $textareaType); + $form = $factory->create(FormType::class, $data, ['data_class' => $this->getClassName()]); + $form->add('text', TextareaType::class); return $form; } diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Admin/News.php b/features/fixtures/project/src/FSi/FixturesBundle/Admin/News.php index 6542283..ed9af54 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Admin/News.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Admin/News.php @@ -1,41 +1,39 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Admin; -use FSi\Bundle\AdminBundle\Annotation as Admin; use FSi\Bundle\AdminBundle\Doctrine\Admin\CRUDElement; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; use FSi\Component\DataGrid\DataGridFactoryInterface; use FSi\Component\DataGrid\DataGridInterface; use FSi\Component\DataSource\DataSourceFactoryInterface; use FSi\Component\DataSource\DataSourceInterface; +use FSi\FixturesBundle\Entity\News as NewsEntity; +use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; -/** - * @Admin\Element - */ class News extends CRUDElement { - /** - * {@inheritDoc} - */ public function getId(): string { return 'admin_news'; } - /** - * {@inheritDoc} - */ public function getClassName(): string { - return 'FSi\FixturesBundle\Entity\News'; + return NewsEntity::class; } - /** - * {@inheritDoc} - */ protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInterface { $datagrid = $factory->createDataGrid($this->getId()); @@ -59,27 +57,18 @@ protected function initDataGrid(DataGridFactoryInterface $factory): DataGridInte return $datagrid; } - /** - * {@inheritDoc} - */ protected function initDataSource(DataSourceFactoryInterface $factory): DataSourceInterface { return $factory->createDataSource('doctrine-orm', ['entity' => $this->getClassName()], $this->getId()); } - /** - * {@inheritDoc} - */ protected function initForm(FormFactoryInterface $factory, $data = null): FormInterface { - $formType = TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\FormType', 'form'); - $textareaType = TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\TextareaType', 'textarea'); - - $form = $factory->create($formType, $data, [ + $form = $factory->create(FormType::class, $data, [ 'data_class' => $this->getClassName(), ]); - $form->add('title', $textareaType, ['label' => 'admin.news.form.title']); + $form->add('title', TextareaType::class, ['label' => 'admin.news.form.title']); return $form; } diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Admin/NonTranslatableResource.php b/features/fixtures/project/src/FSi/FixturesBundle/Admin/NonTranslatableResource.php index f091e58..837ed84 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Admin/NonTranslatableResource.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Admin/NonTranslatableResource.php @@ -1,13 +1,19 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Admin; -use FSi\Bundle\AdminBundle\Annotation as Admin; use FSi\Bundle\AdminBundle\Doctrine\Admin\ResourceElement; +use FSi\FixturesBundle\Entity\Resource; -/** - * @Admin\Element - */ class NonTranslatableResource extends ResourceElement { public function getId(): string @@ -22,6 +28,6 @@ public function getKey(): string public function getClassName(): string { - return 'FSi\FixturesBundle\Entity\Resource'; + return Resource::class; } } diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Admin/TranslatableResource.php b/features/fixtures/project/src/FSi/FixturesBundle/Admin/TranslatableResource.php index 125b9e0..3298796 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Admin/TranslatableResource.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Admin/TranslatableResource.php @@ -1,13 +1,19 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Admin; -use FSi\Bundle\AdminBundle\Annotation as Admin; use FSi\Bundle\AdminTranslatableBundle\Doctrine\Admin\TranslatableResourceElement; +use FSi\FixturesBundle\Entity\Resource; -/** - * @Admin\Element - */ class TranslatableResource extends TranslatableResourceElement { public function getId(): string @@ -22,6 +28,6 @@ public function getKey(): string public function getClassName(): string { - return 'FSi\FixturesBundle\Entity\Resource'; + return Resource::class; } } diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Entity/Comment.php b/features/fixtures/project/src/FSi/FixturesBundle/Entity/Comment.php index 1f7fde3..32e9184 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Entity/Comment.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Entity/Comment.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Entity/CommentTranslation.php b/features/fixtures/project/src/FSi/FixturesBundle/Entity/CommentTranslation.php index 486a946..aee08ce 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Entity/CommentTranslation.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Entity/CommentTranslation.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Entity; use Doctrine\ORM\Mapping as ORM; diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Entity/Event.php b/features/fixtures/project/src/FSi/FixturesBundle/Entity/Event.php index 0082fc5..b97154e 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Entity/Event.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Entity/Event.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Entity/EventTranslation.php b/features/fixtures/project/src/FSi/FixturesBundle/Entity/EventTranslation.php index 4d0d0f1..f3a8d7a 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Entity/EventTranslation.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Entity/EventTranslation.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Entity/File.php b/features/fixtures/project/src/FSi/FixturesBundle/Entity/File.php index 0e4bc5c..c87c2b9 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Entity/File.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Entity/File.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Entity; use Doctrine\ORM\Mapping as ORM; diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Entity/News.php b/features/fixtures/project/src/FSi/FixturesBundle/Entity/News.php index 38cb9fb..5f02e81 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Entity/News.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Entity/News.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Entity; use Doctrine\ORM\Mapping as ORM; diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Entity/Resource.php b/features/fixtures/project/src/FSi/FixturesBundle/Entity/Resource.php index 60ac5a9..339c66f 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Entity/Resource.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Entity/Resource.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Entity; use Doctrine\ORM\Mapping as ORM; diff --git a/features/fixtures/project/src/FSi/FixturesBundle/FSiFixturesBundle.php b/features/fixtures/project/src/FSi/FixturesBundle/FSiFixturesBundle.php index 568ce57..085a155 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/FSiFixturesBundle.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/FSiFixturesBundle.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Form/CommentType.php b/features/fixtures/project/src/FSi/FixturesBundle/Form/CommentType.php index 4745070..db84b26 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Form/CommentType.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Form/CommentType.php @@ -1,33 +1,31 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Form; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; +use FSi\FixturesBundle\Entity\Comment; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; class CommentType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { - $textareaType = TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\TextType', 'text'); - $builder->add('text', $textareaType); + $builder->add('text', TextType::class); } public function configureOptions(OptionsResolver $resolver) { - $resolver->setDefaults(['data_class' => 'FSi\FixturesBundle\Entity\Comment']); - } - - public function setDefaultOptions(OptionsResolverInterface $resolver) - { - $this->configureOptions($resolver); - } - - public function getName() - { - return 'comment'; + $resolver->setDefault('data_class', Comment::class); } } diff --git a/features/fixtures/project/src/FSi/FixturesBundle/Form/FilesType.php b/features/fixtures/project/src/FSi/FixturesBundle/Form/FilesType.php index 2b4401d..a31b26a 100644 --- a/features/fixtures/project/src/FSi/FixturesBundle/Form/FilesType.php +++ b/features/fixtures/project/src/FSi/FixturesBundle/Form/FilesType.php @@ -1,37 +1,31 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + namespace FSi\FixturesBundle\Form; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; +use FSi\Bundle\DoctrineExtensionsBundle\Form\Type\FSi\RemovableFileType; +use FSi\FixturesBundle\Entity\File; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; class FilesType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { - $removableFileType = TypeSolver::getFormType( - 'FSi\Bundle\DoctrineExtensionsBundle\Form\Type\FSi\RemovableFileType', - 'fsi_removable_file' - ); - - $builder->add('file', $removableFileType, ['required' => false]); + $builder->add('file', RemovableFileType::class, ['required' => false]); } public function configureOptions(OptionsResolver $resolver) { - $resolver->setDefaults(['data_class' => 'FSi\FixturesBundle\Entity\File']); - } - - public function setDefaultOptions(OptionsResolverInterface $resolver) - { - $this->configureOptions($resolver); - } - - public function getName() - { - return 'files'; + $resolver->setDefault('data_class', File::class); } } diff --git a/spec/FSi/Bundle/AdminTranslatableBundle/Form/LocaleExtensionSpec.php b/spec/FSi/Bundle/AdminTranslatableBundle/Form/LocaleExtensionSpec.php index 23f5b55..def84f4 100644 --- a/spec/FSi/Bundle/AdminTranslatableBundle/Form/LocaleExtensionSpec.php +++ b/spec/FSi/Bundle/AdminTranslatableBundle/Form/LocaleExtensionSpec.php @@ -12,7 +12,6 @@ namespace spec\FSi\Bundle\AdminTranslatableBundle\Form; use Doctrine\ORM\EntityManagerInterface; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; use FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata; use FSi\DoctrineExtensions\Translatable\TranslatableListener; use PhpSpec\ObjectBehavior; @@ -46,9 +45,7 @@ function it_is_form_extension() function it_extends_from_type() { - $this->getExtendedType()->shouldReturn( - TypeSolver::getFormType(FormType::class, 'form') - ); + $this->getExtendedType()->shouldReturn(FormType::class); } function it_adds_itself_as_form_event_subscriber(FormBuilderInterface $formBuilder) diff --git a/spec/FSi/Bundle/AdminTranslatableBundle/Form/TranslatableCollectionExtensionSpec.php b/spec/FSi/Bundle/AdminTranslatableBundle/Form/TranslatableCollectionExtensionSpec.php index bd5b38f..c29925d 100644 --- a/spec/FSi/Bundle/AdminTranslatableBundle/Form/TranslatableCollectionExtensionSpec.php +++ b/spec/FSi/Bundle/AdminTranslatableBundle/Form/TranslatableCollectionExtensionSpec.php @@ -13,7 +13,6 @@ use FSi\Bundle\AdminTranslatableBundle\Form\TranslatableCollectionListener; use FSi\Bundle\AdminTranslatableBundle\Form\TranslatableFormHelper; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; use PhpSpec\ObjectBehavior; use Symfony\Component\Form\AbstractTypeExtension; use Symfony\Component\Form\Extension\Core\Type\CollectionType; @@ -35,10 +34,7 @@ public function it_is_form_extension() public function it_extends_collection() { - $this->getExtendedType()->shouldReturn(TypeSolver::getFormType( - CollectionType::class, - 'collection' - )); + $this->getExtendedType()->shouldReturn(CollectionType::class); } public function it_adds_listener( diff --git a/spec/FSi/Bundle/AdminTranslatableBundle/Form/TranslatableFSiRemovableFileExtensionSpec.php b/spec/FSi/Bundle/AdminTranslatableBundle/Form/TranslatableFSiRemovableFileExtensionSpec.php index 046fa05..8bdd336 100644 --- a/spec/FSi/Bundle/AdminTranslatableBundle/Form/TranslatableFSiRemovableFileExtensionSpec.php +++ b/spec/FSi/Bundle/AdminTranslatableBundle/Form/TranslatableFSiRemovableFileExtensionSpec.php @@ -12,7 +12,6 @@ namespace spec\FSi\Bundle\AdminTranslatableBundle\Form; use FSi\Bundle\AdminTranslatableBundle\Form\TranslatableFormHelper; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; use FSi\Bundle\DoctrineExtensionsBundle\Form\Type\FSi\RemovableFileType; use FSi\Bundle\DoctrineExtensionsBundle\Resolver\FSiFilePathResolver; use FSi\DoctrineExtensions\Uploadable\File; @@ -42,10 +41,7 @@ function it_is_form_type_extension() function it_extends_text_form() { - $this->getExtendedType()->shouldReturn(TypeSolver::getFormType( - RemovableFileType::class, - 'fsi_removable_file' - )); + $this->getExtendedType()->shouldReturn(RemovableFileType::class); } function it_does_nothing_if_form_has_no_property_path( diff --git a/spec/FSi/Bundle/AdminTranslatableBundle/Form/TranslatableTextExtensionSpec.php b/spec/FSi/Bundle/AdminTranslatableBundle/Form/TranslatableTextExtensionSpec.php index dd0def9..f1f2d7a 100644 --- a/spec/FSi/Bundle/AdminTranslatableBundle/Form/TranslatableTextExtensionSpec.php +++ b/spec/FSi/Bundle/AdminTranslatableBundle/Form/TranslatableTextExtensionSpec.php @@ -14,7 +14,6 @@ use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ORM\EntityManagerInterface; use FSi\Bundle\AdminTranslatableBundle\Form\TranslatableFormHelper; -use FSi\Bundle\AdminTranslatableBundle\Form\TypeSolver; use FSi\DoctrineExtensions\Translatable\Mapping\ClassMetadata; use FSi\DoctrineExtensions\Translatable\TranslatableListener; use PhpSpec\ObjectBehavior; @@ -43,9 +42,7 @@ function it_is_form_type_extension() function it_extends_text_form() { - $this->getExtendedType()->shouldReturn( - TypeSolver::getFormType(TextType::class, 'text') - ); + $this->getExtendedType()->shouldReturn(TextType::class); } function it_does_nothing_if_form_has_no_property_path(