[TASK] Convert remaining ViewHelpers to static calling
[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\ObjectStorage;
17 use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
18 use TYPO3\CMS\Fluid\Core\ViewHelper\Exception;
19
20 /**
21 * This ViewHelper renders a Pagination of objects for the TYPO3 Backend.
22 *
23 * = Examples =
24 *
25 * <code title="required arguments">
26 * <f:be.widget.paginate objects="{blogs}" as="paginatedBlogs">
27 * use {paginatedBlogs} as you used {blogs} before, most certainly inside
28 * a <f:for> loop.
29 * </f:be.widget.paginate>
30 * </code>
31 *
32 * <code title="full configuration">
33 * <f:be.widget.paginate objects="{blogs}" as="paginatedBlogs" configuration="{itemsPerPage: 5, insertAbove: 1, insertBelow: 0, recordsLabel: 'MyRecords'}">
34 * use {paginatedBlogs} as you used {blogs} before, most certainly inside
35 * a <f:for> loop.
36 * </f:be.widget.paginate>
37 * The recordsLabel can be used to replace the text in "Records 1 - 99" with a label of your own choice
38 * </code>
39 *
40 * = Performance characteristics =
41 *
42 * In the above examples, it looks like {blogs} contains all Blog objects, thus
43 * you might wonder if all objects were fetched from the database.
44 * However, the blogs are NOT fetched from the database until you actually use them,
45 * so the paginate ViewHelper will adjust the query sent to the database and receive
46 * only the small subset of objects.
47 * So, there is no negative performance overhead in using the Be Paginate Widget.
48 *
49 * @api
50 */
51 class PaginateViewHelper extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper
52 {
53 /**
54 * @var \TYPO3\CMS\Fluid\ViewHelpers\Be\Widget\Controller\PaginateController
55 */
56 protected $controller;
57
58 /**
59 * @param \TYPO3\CMS\Fluid\ViewHelpers\Be\Widget\Controller\PaginateController $controller
60 */
61 public function injectPaginateController(\TYPO3\CMS\Fluid\ViewHelpers\Be\Widget\Controller\PaginateController $controller)
62 {
63 $this->controller = $controller;
64 }
65
66 /**
67 * Initialize arguments.
68 */
69 public function initializeArguments()
70 {
71 parent::initializeArguments();
72 $this->registerArgument('objects', 'mixed', 'Object', true);
73 $this->registerArgument('as', 'string', 'as', true);
74 $this->registerArgument('configuration', 'array', 'configuration', false, ['itemsPerPage' => 10, 'insertAbove' => false, 'insertBelow' => true, 'maximumNumberOfLinks' => 99]);
75 }
76
77 /**
78 * @throws Exception
79 * @return string
80 */
81 public function render()
82 {
83 $objects = $this->arguments['objects'];
84
85 if (!($objects instanceof QueryResultInterface || $objects instanceof ObjectStorage || is_array($objects))) {
86 throw new Exception('Supplied file object type ' . get_class($objects) . ' must be QueryResultInterface or ObjectStorage or be an array.', 1454510732);
87 }
88 return $this->initiateSubRequest();
89 }
90 }