Skip to content

Commit

Permalink
Added missing shortcut addAjaxBlock() and isAjax() method
Browse files Browse the repository at this point in the history
- Better management of ajax requests in controllers
  • Loading branch information
jelen07 committed Aug 16, 2018
1 parent 2e9d21c commit 4618317
Showing 1 changed file with 17 additions and 1 deletion.
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;
}
}

0 comments on commit 4618317

Please sign in to comment.