Skip to content

Commit

Permalink
Merge pull request #13 from jelen07/change_url
Browse files Browse the repository at this point in the history
Change url
  • Loading branch information
ostrolucky committed Aug 16, 2018
2 parents c7a3437 + 1e72f3c commit 5c366d5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<script type="text/javascript" src="{{ asset('build/ajaxcom.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('build/ajaxcom.js') }}"></script>
```

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).
Expand All @@ -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'
Expand Down
18 changes: 17 additions & 1 deletion src/Controller/AjaxcomSymfony4Trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/EverlutionAjaxcomExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 3 additions & 2 deletions src/Mutation/ChangeUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ services:
arguments:
- '@request_stack'
- '@router.default'
- '%everlution.ajaxcom.change_url%'

ajaxcom.mutation.flash_messages:
class: Everlution\AjaxcomBundle\Mutation\FlashMessages
Expand Down

0 comments on commit 5c366d5

Please sign in to comment.