-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathListingController.php
65 lines (51 loc) · 2.31 KB
/
ListingController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace Bolt\Controller\Backend;
use Bolt\Configuration\Content\ContentType;
use Bolt\Controller\TwigAwareController;
use Bolt\Entity\Content;
use Bolt\Security\ContentVoter;
use Bolt\Storage\Query;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class ListingController extends TwigAwareController implements BackendZoneInterface
{
/**
* @Route("/content/{contentType}", name="bolt_content_overview")
*/
public function overview(Query $query, string $contentType = ''): Response
{
$contentTypeObject = ContentType::factory($contentType, $this->config->get('contenttypes'));
$this->denyAccessUnlessGranted(ContentVoter::CONTENT_MENU_LISTING, $contentTypeObject);
$page = (int) $this->getFromRequest('page', '1');
$pager = $this->createPager($query, $contentType, $contentTypeObject->get('records_per_page'), $contentTypeObject->get('order'));
$nbPages = $pager->getNbPages();
if ($page > $nbPages) {
return $this->redirectToRoute('bolt_content_overview', [
'contentType' => $contentType,
'page' => $nbPages,
]);
}
$records = $pager->setCurrentPage($page);
if ($contentTypeObject->get('singleton', false) === true) {
if ($records->getNbResults() === 0) {
// No such CT yet. Create new.
return $this->redirectToRoute('bolt_content_new', ['contentType' => $contentType]);
}
// Redirect to the record
/** @var Content $record */
$record = current((array) $records->getCurrentPageResults());
return $this->redirectToRoute('bolt_content_edit', ['id' => $record->getId()]);
}
[$taxonomyName, $taxonomyValue] = explode('=', $this->getFromRequest('taxonomy', '') . '=');
return $this->render('@bolt/content/listing.html.twig', [
'contentType' => $contentTypeObject,
'records' => $records,
'sortBy' => $this->getFromRequest('sortBy'),
'filterValue' => $this->getFromRequest('filter'),
'taxonomyName' => $taxonomyName,
'taxonomyValue' => $taxonomyValue,
'filterKey' => $this->getFromRequest('filterKey'),
]);
}
}