From 2e9d21c2217669ea9ed922872acf9e49e879b16b Mon Sep 17 00:00:00 2001 From: Vojtech Lacina Date: Thu, 16 Aug 2018 14:01:32 +0000 Subject: [PATCH 1/3] Change URL behavior is now configurable - By default is on --- README.md | 1 + src/DependencyInjection/Configuration.php | 2 ++ src/DependencyInjection/EverlutionAjaxcomExtension.php | 1 + src/Mutation/ChangeUrl.php | 5 +++-- src/Resources/config/services.yml | 1 + 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 949c580..4ad6333 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ everlution_ajaxcom: flash_template: @EverlutionAjaxcom/flash_message.html.twig flash_block_id: flash_message persistent_class: ajaxcom-persistent + change_url: true blocks_to_render: # default value is empty array - when you provide this value, AjaxcomBundle will automatically render these blocks within each AJAX request - id: 'content' - id: 'navigation' diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 8d91ddd..f8d5e97 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -18,6 +18,7 @@ class Configuration implements ConfigurationInterface const FLASH_BLOCK_ID = 'flash_block_id'; const PERSISTENT_CLASS = 'persistent_class'; const BLOCKS_TO_RENDER = 'blocks_to_render'; + const CHANGE_URL = 'change_url'; const ID = 'id'; const REFRESH = 'refresh'; @@ -31,6 +32,7 @@ public function getConfigTreeBuilder() ->scalarNode(self::FLASH_TEMPLATE)->defaultValue('@EverlutionAjaxcom/flash_message.html.twig')->end() ->scalarNode(self::FLASH_BLOCK_ID)->defaultValue('flash_message')->end() ->scalarNode(self::PERSISTENT_CLASS)->defaultValue('ajaxcom-persistent')->end() + ->scalarNode(self::CHANGE_URL)->defaultTrue()->end() ->arrayNode(self::BLOCKS_TO_RENDER) ->arrayPrototype() ->children() diff --git a/src/DependencyInjection/EverlutionAjaxcomExtension.php b/src/DependencyInjection/EverlutionAjaxcomExtension.php index ced9e54..181813d 100644 --- a/src/DependencyInjection/EverlutionAjaxcomExtension.php +++ b/src/DependencyInjection/EverlutionAjaxcomExtension.php @@ -26,6 +26,7 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('everlution.ajaxcom.flash_block_id', $config[C::FLASH_BLOCK_ID]); $container->setParameter('everlution.ajaxcom.persistent_class', $config[C::PERSISTENT_CLASS]); $container->setParameter('everlution.ajaxcom.blocks_to_render', $config[C::BLOCKS_TO_RENDER]); + $container->setParameter('everlution.ajaxcom.change_url', $config[C::CHANGE_URL]); $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); diff --git a/src/Mutation/ChangeUrl.php b/src/Mutation/ChangeUrl.php index 1847082..ac70e61 100644 --- a/src/Mutation/ChangeUrl.php +++ b/src/Mutation/ChangeUrl.php @@ -22,12 +22,13 @@ class ChangeUrl implements MutatorInterface /** @var UrlGeneratorInterface */ private $router; /** @var bool */ - private $changeUrl = true; + private $changeUrl; - public function __construct(RequestStack $requestStack, UrlGeneratorInterface $router) + public function __construct(RequestStack $requestStack, UrlGeneratorInterface $router, bool $changeUrl) { $this->router = $router; $this->request = $requestStack->getMasterRequest(); + $this->changeUrl = $changeUrl; } public function mutate(Handler $ajax): Handler diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index 902eec4..f0ea151 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -79,6 +79,7 @@ services: arguments: - '@request_stack' - '@router.default' + - '%everlution.ajaxcom.change_url%' ajaxcom.mutation.flash_messages: class: Everlution\AjaxcomBundle\Mutation\FlashMessages From 4618317a56c74bc52cd51dba92f033b721ad23d2 Mon Sep 17 00:00:00 2001 From: Vojtech Lacina Date: Thu, 16 Aug 2018 14:04:31 +0000 Subject: [PATCH 2/3] Added missing shortcut addAjaxBlock() and isAjax() method - Better management of ajax requests in controllers --- src/Controller/AjaxcomSymfony4Trait.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Controller/AjaxcomSymfony4Trait.php b/src/Controller/AjaxcomSymfony4Trait.php index 88563d8..9d4d8a0 100644 --- a/src/Controller/AjaxcomSymfony4Trait.php +++ b/src/Controller/AjaxcomSymfony4Trait.php @@ -76,7 +76,7 @@ protected function render(string $view, array $parameters = array(), Response $r { $request = $this->requestStack->getMasterRequest(); - if ($request->server->get(Ajaxcom::AJAX_COM_HEADER, false)) { + if ($this->isAjax()) { return $this->ajaxcom->handle($view, $parameters); } @@ -97,6 +97,13 @@ protected function dontRenderAjaxBlock(string $id): self return $this; } + protected function addAjaxBlock(string $id): self + { + $this->ajaxcomAddBlocks->add($id); + + return $this; + } + protected function appendAjaxBlock(string $id): self { $this->ajaxcomAppendBlocks->add($id); @@ -145,4 +152,13 @@ protected function prependAjaxBlock(string $id): self return $this; } + + protected function isAjax(): bool + { + /** @var Request $request */ + $request = $this->requestStack->getMasterRequest(); + $isAjax = $request->server->getBoolean(Ajaxcom::AJAX_COM_HEADER, false); + + return $isAjax; + } } From 1e72f3c79b0b8e8d6c0a2e1986315130e8ef7361 Mon Sep 17 00:00:00 2001 From: Vojtech Lacina Date: Thu, 16 Aug 2018 14:07:35 +0000 Subject: [PATCH 3/3] Updated README.md - There is no minified version of ajaxcom.js --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4ad6333..16e4854 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,10 @@ class AppKernel extends Kernel ### Step 3: Include Ajaxcom library JavasSript within your TWIG layout -Install `@everlutionsk/ajaxcom-js` via `npm` and include `ajaxcom.min.js` to your TWIG layout: +Install `@everlutionsk/ajaxcom-js` via `npm` and include `ajaxcom.js` to your TWIG layout: ```twig - + ``` The last thing you need to do is provide some JavaScript handler within your TWIG layout - please follow `@everlutionsk/ajaxcom-js` [documentation](https://github.com/everlutionsk/ajaxcom-js).