Add BG offset
This commit is contained in:
1 parent
c720696781
commit
58990ebe8d
6 files changed
+161
-5
No files matched your search
@@ -11,6 +11,7 @@ use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Resource\ResourceFactory;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use Evomedien\Vitec\Service\LinkResolver;
|
||||
use Evomedien\Vitec\Service\RteResolver;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
@@ -326,13 +327,14 @@ final class NewsJsonRenderer
|
||||
{
|
||||
$uid = (int)($news['uid'] ?? 0);
|
||||
$pathSegment = (string)($news['path_segment'] ?? '');
|
||||
$urls = $this->buildNewsUrls($pathSegment, $settings);
|
||||
$urls = $this->buildNewsUrls($news, $settings);
|
||||
|
||||
return [
|
||||
'uid' => $uid,
|
||||
'title' => (string)($news['title'] ?? ''),
|
||||
'alternativeTitle' => (string)($news['alternative_title'] ?? ''),
|
||||
'pathSegment' => $pathSegment,
|
||||
'type' => (string)($news['type'] ?? '0'),
|
||||
'detailUrl' => $urls['detailUrl'],
|
||||
'canonicalUrl' => $urls['canonicalUrl'],
|
||||
'teaser' => (string)($news['teaser'] ?? ''),
|
||||
@@ -352,12 +354,52 @@ final class NewsJsonRenderer
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a news item actually points.
|
||||
*
|
||||
* EXT:news knows three record types, and only the first one lives on the
|
||||
* news detail route:
|
||||
*
|
||||
* 0 article -> detail page + path_segment (the default below)
|
||||
* 1 internal page -> the page picked in the backend; the record itself
|
||||
* carries no body, so linking it to the detail route
|
||||
* would show a teaser and hide the actual content
|
||||
* 2 external url -> the given address, verbatim
|
||||
*
|
||||
* `detailUrl` is rewritten rather than accompanied by a second field, so a
|
||||
* consumer can keep following one key for every item and never has to branch
|
||||
* on the type. `type` is emitted alongside anyway — a front end may well want
|
||||
* to open an external target in a new tab.
|
||||
*
|
||||
* Falls back to the article URL whenever a type 1/2 record does not yield a
|
||||
* usable target: a link to the teaser beats a dead one.
|
||||
*
|
||||
* @param array<string,mixed> $news
|
||||
* @param array<string,mixed> $settings
|
||||
* @return array{detailUrl:string, canonicalUrl:string}
|
||||
*/
|
||||
private function buildNewsUrls(string $pathSegment, array $settings): array
|
||||
private function buildNewsUrls(array $news, array $settings): array
|
||||
{
|
||||
$pathSegment = trim($pathSegment, '/');
|
||||
$type = (string)($news['type'] ?? '0');
|
||||
|
||||
if ($type === '2') {
|
||||
$external = trim((string)($news['externalurl'] ?? ''));
|
||||
if ($external !== '') {
|
||||
return ['detailUrl' => $external, 'canonicalUrl' => $external];
|
||||
}
|
||||
}
|
||||
|
||||
if ($type === '1') {
|
||||
$pageUid = $this->extractPageUid((string)($news['internalurl'] ?? ''));
|
||||
$pageUrl = $pageUid > 0 ? LinkResolver::pageUrl($pageUid) : null;
|
||||
if ($pageUrl !== null && $pageUrl !== '') {
|
||||
return [
|
||||
'detailUrl' => $pageUrl,
|
||||
'canonicalUrl' => $this->absoluteUrl($pageUrl),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$pathSegment = trim((string)($news['path_segment'] ?? ''), '/');
|
||||
if ($pathSegment === '') {
|
||||
return ['detailUrl' => '', 'canonicalUrl' => ''];
|
||||
}
|
||||
@@ -380,6 +422,19 @@ final class NewsJsonRenderer
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* `internalurl` holds either `t3://page?uid=N` or a bare uid, depending on
|
||||
* how old the record is - the legacy import produced both forms.
|
||||
*/
|
||||
private function extractPageUid(string $internalUrl): int
|
||||
{
|
||||
$internalUrl = trim($internalUrl);
|
||||
if (preg_match('#t3://page\?uid=(\d+)#i', $internalUrl, $m)) {
|
||||
return (int)$m[1];
|
||||
}
|
||||
return ctype_digit($internalUrl) ? (int)$internalUrl : 0;
|
||||
}
|
||||
|
||||
private function resolvePageSlug(int $pageId): string
|
||||
{
|
||||
if ($pageId <= 0) {
|
||||
|
||||
Reference in new issue
Block a user