Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Modernize cObject "USER" example #1328

Merged
Merged
Changes from 1 commit
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!
sfroemkenjw marked this conversation as resolved.
Show resolved Hide resolved
*/
#[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);
}
}