-
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
619 additions
and
99 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' } |
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kunstmaan\ArticleBundle\ViewDataProvider; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
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(RenderContext $renderContext): void | ||
{ | ||
$request = $this->requestStack->getMasterRequest(); | ||
if (null === $request) { | ||
return; | ||
} | ||
|
||
$entity = $request->attributes->get('_entity'); | ||
$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
49 changes: 49 additions & 0 deletions
49
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kunstmaan\FormBundle\ViewDataProvider; | ||
|
||
use Kunstmaan\FormBundle\Helper\FormHandlerInterface; | ||
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; | ||
|
||
public function __construct(RequestStack $requestStack, FormHandlerInterface $formHandler) | ||
{ | ||
$this->requestStack = $requestStack; | ||
$this->formHandler = $formHandler; | ||
} | ||
|
||
public function provideViewData(RenderContext $renderContext): void | ||
{ | ||
$request = $this->requestStack->getMasterRequest(); | ||
if (null === $request) { | ||
return; | ||
} | ||
|
||
$thanksParam = $request->get('thanks'); | ||
$entity = $request->attributes->get('_entity'); | ||
$renderContext['nodetranslation'] = $request->attributes->get('_nodeTranslation'); | ||
$renderContext['slug'] = $request->attributes->get('url'); | ||
$renderContext['page'] = $entity; | ||
$renderContext['resource'] = $entity; | ||
|
||
if (!empty($thanksParam)) { | ||
$renderContext['resource'] = 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.