diff --git a/README.md b/README.md
index 949c580..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).
@@ -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/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;
+ }
}
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