-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NodeBundle] Deprecate SlugActionInterface and replace it by PageRend…
…er setup
- Loading branch information
Showing
38 changed files
with
636 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
parameters: | ||
|
||
services: | ||
kunstmaan_articlebundle.twig.extension: | ||
class: 'Kunstmaan\ArticleBundle\Twig\ArticleTwigExtension' | ||
arguments: ['@doctrine.orm.entity_manager', '@router'] | ||
tags: | ||
- { name: twig.extension } | ||
|
||
Kunstmaan\ArticleBundle\ViewDataProvider\ArticlePageViewDataProvider: | ||
arguments: [ '@doctrine.orm.entity_manager', '@request_stack' ] | ||
tags: | ||
- { name: 'kunstmaan.node.page_view_data_provider' } |
51 changes: 51 additions & 0 deletions
51
src/Kunstmaan/ArticleBundle/ViewDataProvider/ArticlePageViewDataProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kunstmaan\ArticleBundle\ViewDataProvider; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Kunstmaan\NodeBundle\Entity\NodeTranslation; | ||
use Kunstmaan\NodeBundle\Entity\PageViewDataProviderInterface; | ||
use Kunstmaan\NodeBundle\Helper\RenderContext; | ||
use Pagerfanta\Adapter\ArrayAdapter; | ||
use Pagerfanta\Pagerfanta; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
|
||
final class ArticlePageViewDataProvider implements PageViewDataProviderInterface | ||
{ | ||
/** @var EntityManagerInterface */ | ||
private $em; | ||
/** @var RequestStack */ | ||
private $requestStack; | ||
|
||
public function __construct(EntityManagerInterface $em, RequestStack $requestStack) | ||
{ | ||
$this->em = $em; | ||
$this->requestStack = $requestStack; | ||
} | ||
|
||
public function provideViewData(NodeTranslation $nodeTranslation, RenderContext $renderContext): void | ||
{ | ||
$request = $this->requestStack->getMasterRequest(); | ||
if (null === $request) { | ||
return; | ||
} | ||
|
||
$entity = $nodeTranslation->getRef($this->em); | ||
$repository = $entity->getArticleRepository($this->em); | ||
$pages = $repository->getArticles($request->getLocale()); | ||
|
||
$adapter = new ArrayAdapter($pages); | ||
$pagerfanta = new Pagerfanta($adapter); | ||
$pagerfanta->setMaxPerPage(5); | ||
|
||
$pagenumber = $request->get('page'); | ||
if (!$pagenumber || $pagenumber < 1) { | ||
$pagenumber = 1; | ||
} | ||
|
||
$pagerfanta->setCurrentPage($pagenumber); | ||
$renderContext['pagerfanta'] = $pagerfanta; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/Kunstmaan/FormBundle/ViewDataProvider/FormPageViewDataProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kunstmaan\FormBundle\ViewDataProvider; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Kunstmaan\FormBundle\Helper\FormHandlerInterface; | ||
use Kunstmaan\NodeBundle\Entity\NodeTranslation; | ||
use Kunstmaan\NodeBundle\Entity\PageViewDataProviderInterface; | ||
use Kunstmaan\NodeBundle\Helper\RenderContext; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class FormPageViewDataProvider implements PageViewDataProviderInterface | ||
{ | ||
/** @var RequestStack */ | ||
private $requestStack; | ||
/** @var FormHandlerInterface */ | ||
private $formHandler; | ||
/** @var EntityManagerInterface */ | ||
private $em; | ||
|
||
public function __construct(RequestStack $requestStack, FormHandlerInterface $formHandler, EntityManagerInterface $em) | ||
{ | ||
$this->requestStack = $requestStack; | ||
$this->formHandler = $formHandler; | ||
$this->em = $em; | ||
} | ||
|
||
public function provideViewData(NodeTranslation $nodeTranslation, RenderContext $renderContext): void | ||
{ | ||
$request = $this->requestStack->getMasterRequest(); | ||
if (null === $request) { | ||
return; | ||
} | ||
|
||
$thanksParam = $request->get('thanks'); | ||
$entity = $nodeTranslation->getRef($this->em); | ||
$renderContext['nodetranslation'] = $nodeTranslation; | ||
$renderContext['slug'] = $request->attributes->get('url'); | ||
$renderContext['page'] = $entity; | ||
$renderContext['resource'] = $entity; | ||
|
||
if (!empty($thanksParam)) { | ||
$renderContext['thanks'] = true; | ||
} | ||
|
||
$result = $this->formHandler->handleForm($entity, $request, $renderContext); | ||
if ($result instanceof Response) { | ||
$renderContext->setResponse($result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.