[TASK] Make DbTableViewHelper compatible to TYPO3 9

This commit is contained in:
Philipp Dieter 2021-06-23 14:35:30 +02:00
parent 4b78ff8eaf
commit b2a7731311

View File

@ -4,27 +4,46 @@ namespace Cjel\TemplatesAide\ViewHelpers;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\Connection;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
class DbTableViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper { class DbTableViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/** /**
* As this ViewHelper renders HTML, the output must not be escaped. * As this ViewHelper renders HTML, the output must not be escaped.
* *
* @var bool * @var bool
*/ */
protected $escapeOutput = false; protected $escapeOutput = false;
/** /**
* @param string $table The filename * Initialize arguments
* @param string $fields The filename */
* @param string $where public function initializeArguments() {
* @param string $orderBy parent::initializeArguments();
$this->registerArgument('table', 'string', '', true);
$this->registerArgument('fields', 'array', '', true, ['*']);
$this->registerArgument('where', 'array', '', true);
$this->registerArgument('orderBy', 'array', '', true);
}
/**
* @param string $table
* @param array $fields
* @param array $where
* @param array $orderBy
* @return string HTML Content * @return string HTML Content
*/ */
public function render($table, $fields = ['*'], $where = [], $orderBy = []){ public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$table = $arguments['table'];
$fields = $arguments['fields'];
$where = $arguments['where'];
$orderBy = $arguments['orderBy'];
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table)->createQueryBuilder();
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages')->createQueryBuilder();
$whereExpressions = []; $whereExpressions = [];
if (!empty($where)) { if (!empty($where)) {