Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@
namespace MyVendor\SitePackage\UserFunctions;

use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

/**
* Example of a method in a PHP class to be called from TypoScript
*
* The class is defined as public as we use dependency injection in
* this example. If you do not need dependency injection, the
* "Autoconfigure" attribute should be omitted!
*/
#[Autoconfigure(public: true)]
final class ExampleListRecords
{
public function __construct(
private readonly ConnectionPool $connectionPool,
) {}

/**
* Reference to the parent (calling) cObject set from TypoScript
*/
Expand All @@ -33,18 +42,18 @@ public function setContentObjectRenderer(ContentObjectRenderer $cObj): void
*/
public function listContentRecordsOnPage(string $content, array $conf, ServerRequestInterface $request): string
{
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
$connection = $this->connectionPool->getConnectionForTable('tt_content');
$result = $connection->select(
['header'],
'tt_content',
['pid' => (int)$GLOBALS['TSFE']->id],
['pid' => $request->getAttribute('frontend.page.information')->getId()],
[],
['sorting' => $conf['reverseOrder'] ? 'DESC' : 'ASC'],
);
$output = [];
foreach ($result as $row) {
$output[] = $row['header'];
}
return implode('<br />', $output);
return implode('<br>', $output);
}
}