diff --git a/README.md b/README.md index a0abb01..5f987e2 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ UX Collection JS requires PHP 7.4+ and Symfony 4.4+. Install this bundle using Composer and Symfony Flex: ```sh -composer require tienvx/ux-collection-js +composer require tienvx/ux-collection-js:^1.0@alpha # Don't forget to install the JavaScript dependencies as well and compile yarn add --dev '@symfony/stimulus-bridge@^2.0.0' @@ -19,26 +19,27 @@ yarn encore dev ## Usage +### Symfony + Use the new CollectionType class defined by this bundle: ```php // ... use Tienvx\UX\CollectionJs\Form\CollectionJsType; -class TaskType extends AbstractType +class PostType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder // ... - ->add('tags', CollectionJsType::class, [ - 'entry_type' => TextType::class, + ->add('attachments', CollectionJsType::class, [ + 'entry_type' => FileType::class, 'allow_add' => true, - 'allow_remove' => true, + 'allow_delete' => true, 'allow_move_up' => true, 'allow_move_down' => true, 'call_post_add_on_init' => true, - 'prototype' => true, ]) // ... ; @@ -48,13 +49,9 @@ class TaskType extends AbstractType } ``` -Then you need to set the form theme: -```yaml -# config/packages/twig.yaml -twig: - # For bootstrap for example - form_themes: ['@CollectionJs/bootstrap_5_layout.html.twig'] -``` +### Easyadmin + +TBD ## Contributing Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. diff --git a/composer.json b/composer.json index 88fb11f..a9b3771 100644 --- a/composer.json +++ b/composer.json @@ -30,13 +30,16 @@ }, "require": { "php": "^7.4|^8.0", + "symfony/config": "^4.4|^5.0", "symfony/dependency-injection": "^4.4.17|^5.0", "symfony/form": "^4.4.17|^5.0", - "symfony/http-kernel": "^4.4.17|^5.0" + "symfony/http-kernel": "^4.4.17|^5.0", + "twig/twig": "^2.12|^3.0" }, "require-dev": { "phpunit/phpunit": "^9.5", - "symfony/framework-bundle": "^4.4.17|^5.0" + "symfony/framework-bundle": "^4.4.17|^5.0", + "symfony/twig-bundle": "^4.4.17|^5.0" }, "conflict": { "symfony/flex": "<1.13" diff --git a/src/DependencyInjection/CollectionJsExtension.php b/src/DependencyInjection/CollectionJsExtension.php new file mode 100644 index 0000000..5edab72 --- /dev/null +++ b/src/DependencyInjection/CollectionJsExtension.php @@ -0,0 +1,30 @@ +getParameter('kernel.bundles'); + + if (!isset($bundles['TwigBundle'])) { + return; + } + + $container->prependExtensionConfig('twig', ['form_themes' => ['@CollectionJs/bootstrap_5_layout.html.twig']]); + } + + public function load(array $configs, ContainerBuilder $container) + { + $loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader->load('services.php'); + } +} diff --git a/src/Form/CollectionJsType.php b/src/Form/CollectionJsType.php index c3ae97a..558e315 100644 --- a/src/Form/CollectionJsType.php +++ b/src/Form/CollectionJsType.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Tienvx\UX\CollectionJs\Form; use Symfony\Component\Form\AbstractType; diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index 9b33324..b64bfc9 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -3,10 +3,13 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; use Tienvx\UX\CollectionJs\Form\CollectionJsType; +use Tienvx\UX\CollectionJs\Twig\CollectionJsTwigExtension; return static function (ContainerConfigurator $container): void { $container->services() ->set(CollectionJsType::class) ->tag('form.type') + ->set(CollectionJsTwigExtension::class) + ->tag('twig.extension') ; }; diff --git a/src/Resources/views/bootstrap_5_layout.html.twig b/src/Resources/views/bootstrap_5_layout.html.twig index b8fcc24..57d67e8 100644 --- a/src/Resources/views/bootstrap_5_layout.html.twig +++ b/src/Resources/views/bootstrap_5_layout.html.twig @@ -38,11 +38,7 @@