[BUGFIX] Only allow QueryResultInterface in Be.PaginateViewHelper
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / Widget / PaginateViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Widget;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
17
18 /**
19 * This ViewHelper renders a Pagination of objects for the TYPO3 Backend.
20 *
21 * = Examples =
22 *
23 * <code title="required arguments">
24 * <f:be.widget.paginate objects="{blogs}" as="paginatedBlogs">
25 * use {paginatedBlogs} as you used {blogs} before, most certainly inside
26 * a <f:for> loop.
27 * </f:be.widget.paginate>
28 * </code>
29 *
30 * <code title="full configuration">
31 * <f:be.widget.paginate objects="{blogs}" as="paginatedBlogs" configuration="{itemsPerPage: 5, insertAbove: 1, insertBelow: 0, recordsLabel: 'MyRecords'}">
32 * use {paginatedBlogs} as you used {blogs} before, most certainly inside
33 * a <f:for> loop.
34 * </f:be.widget.paginate>
35 * The recordsLabel can be used to replace the text in "Records 1 - 99" with a label of your own choice
36 * </code>
37 *
38 * = Performance characteristics =
39 *
40 * In the above examples, it looks like {blogs} contains all Blog objects, thus
41 * you might wonder if all objects were fetched from the database.
42 * However, the blogs are NOT fetched from the database until you actually use them,
43 * so the paginate ViewHelper will adjust the query sent to the database and receive
44 * only the small subset of objects.
45 * So, there is no negative performance overhead in using the Be Paginate Widget.
46 *
47 * @api
48 */
49 class PaginateViewHelper extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper
50 {
51 /**
52 * @var \TYPO3\CMS\Fluid\ViewHelpers\Be\Widget\Controller\PaginateController
53 */
54 protected $controller;
55
56 /**
57 * @param \TYPO3\CMS\Fluid\ViewHelpers\Be\Widget\Controller\PaginateController $controller
58 */
59 public function injectPaginateController(\TYPO3\CMS\Fluid\ViewHelpers\Be\Widget\Controller\PaginateController $controller)
60 {
61 $this->controller = $controller;
62 }
63
64 /**
65 * Initialize arguments.
66 */
67 public function initializeArguments()
68 {
69 parent::initializeArguments();
70 $this->registerArgument('objects', QueryResultInterface::class, 'The QueryResult containing all objects.', true);
71 $this->registerArgument('as', 'string', 'as', true);
72 $this->registerArgument('configuration', 'array', 'configuration', false, ['itemsPerPage' => 10, 'insertAbove' => false, 'insertBelow' => true, 'maximumNumberOfLinks' => 99]);
73 }
74
75 /**
76 * @return string
77 */
78 public function render()
79 {
80 return $this->initiateSubRequest();
81 }
82 }