news icon indicating copy to clipboard operation
news copied to clipboard

Set news detail view PID in TypoScript but from site configuration settings

Open einpraegsam opened this issue 8 months ago • 1 comments

We have a large instance with TYPO3 13 and news 12.2.0 with a lot of sites. The project requires to set the detail PID via site configuration.

I'm not sure if there is a solution yet that i've overseen, but we replaced the LinkViewHelper in news with our own LinkViewHelper. Here we overruled getDetailPidFromDefaultDetailPid(). Like this:

<?php

declare(strict_types=1);

namespace In2code\In2template\ViewHelpers\News;

use GeorgRinger\News\ViewHelpers\LinkViewHelper as LinkViewHelperOriginal;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

final class LinkViewHelper extends LinkViewHelperOriginal
{
    private ContentObjectRenderer $contentObjectRenderer;

    public function injectContentObjectRenderer(ContentObjectRenderer $contentObjectRenderer): void
    {
        $this->contentObjectRenderer = $contentObjectRenderer;
    }

    /**
     * Overrule getDetailPidFromDefaultDetailPid()
     * to be able to use site configuration values in settings.defaultDetailPid
     *
     * @param $settings
     * @param $newsItem
     * @return int
     */
    protected function getDetailPidFromDefaultDetailPid($settings, $newsItem): int
    {
        unset($newsItem);
        $pageIdentifier = (int)$this->contentObjectRenderer->cObjGetSingle(
            $settings['defaultDetailPid']['_typoScriptNodeValue'] ?? '',
            $settings['defaultDetailPid'] ?? ''
        );
        if ($pageIdentifier === 0) {
            $pageIdentifier = $settings['defaultDetailPid'] ?? 0;
        }
        return $pageIdentifier;
    }
}

Now it's possible to use TypoScript like:

plugin.tx_news {
    settings {
        defaultDetailPid = TEXT
        defaultDetailPid.data = site:settings.uid.newsDetailView
    }
}

The settings.yaml:

uid:
  newsDetailView: 1146

This solution is no breaking change because the old way is still supported: plugin.tx_news.settings.defaultDetailPid=123

If there is already a solution for this, just close this issue.

Greetings, Alex

einpraegsam avatar May 06 '25 12:05 einpraegsam

Same setup here (13 + multi sites with different news pids from site settings.yaml) and this TypoScript config works:

plugin.tx_news {
  settings {
    listPid = {$pids.news.list}
    detailPid = {$pids.news.detail}
    defaultDetailPid = {$pids.news.detail}
    startingpoint = {$pids.news.storage}
  }
}

I do think that defaultDetailPid was not enough for some reason, but using the exact constant in detailPid worked. Also make sure there are no pids specified in the plugin instance (if manually created in the backend), I think they override the TypoScript defaults.

carsanwitt avatar May 22 '25 10:05 carsanwitt

Thanks @einpraegsam for the issue. I fixed that in main a bit different by using site set settings and those configuration in the link generation as fallback. Feel free to test it out

georgringer avatar Oct 09 '25 17:10 georgringer