Files
VITEC-website/packages/fe_comment/Classes/UserFunc/OverviewJsonRenderer.php
T
orasche eb0d0d9ebc fe_comment: Feedback Overview content element in the page JSON
- New content element "Feedback Overview" (CType fecomment_overview):
  the current FE user's feedback state under content.feedbackOverview,
  so the overview page renders like any other page instead of a
  front-end special case
- Rendered as USER_INT inside the cached page JSON (EXT:headless replaces
  the field per request): data is per user, visitors without a session
  get {"allowed": false} - verified that nothing leaks from the cache
- One implementation for both consumers: the new FeedbackState service
  builds the state payload; the API middleware delegates to it
- State payload (API and element) gained canSubmit and actions (all
  write endpoints with method and URL), so the front end needs no
  hard-coded endpoints for the submit button below the ticket list
- New site set evomedien/fe-comment carries the TypoScript, added to the
  site configuration; icon fecomment-overview
2026-10-09 14:56:10 +02:00

37 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Evomedien\FeComment\UserFunc;
use Evomedien\FeComment\Service\FeedbackState;
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* "Feedback Overview" content element (CType fecomment_overview,
* 2026-10-09): the current FE user's feedback state in the page JSON, under
* content.feedbackOverview - exactly the payload of GET
* /api/fe-comment/state (shared FeedbackState service), so a front end can
* render the overview page like any other page.
*
* Wired as USER_INT: the data is per user. EXT:headless keeps the page
* cached and replaces only this field per request. Visitors who are not
* allowed get {"allowed": false} (front end: redirect to the login page).
*/
final class OverviewJsonRenderer
{
#[AsAllowedCallable]
public function render(string $content, array $conf): string
{
try {
$request = $GLOBALS['TYPO3_REQUEST'] ?? null;
$state = GeneralUtility::makeInstance(FeedbackState::class);
$payload = $request !== null ? $state->payload($state->allowedUser($request)) : ['allowed' => false];
} catch (\Throwable) {
$payload = ['allowed' => false];
}
return (string)json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
}
}