I'm trying to send a get parameter to a userFunc
in order to identify a page, but it doesn't seem to work. This is what I have:
########## CATEGORY CONTENT ##########
lib.categoryContent = COA
lib.categoryContent {
10 < styles.content.get
10 {
select {
pidInList.cObject = USER
pidInList.cObject {
userFunc = Vendor\Provider\UserFunc\PageIdByAlias->getPageIdByAlias
alias = TEXT
alias.data = GP:category
}
}
}
wrap = <categoryContent><![CDATA[|]]></categoryContent>
}
And in PHP:
/**
* Returns page ID by alias
*
* @return int
*/
public function getPageIdByAlias($content, $conf)
{
$pageId = $this->pageRepository->getPageIdByAlias($conf["alias"]);
return $pageId;
}
I have also tried:
alias.cObject = TEXT
alias.cObject.data = GP:category
But still, I only get the string GP:category
in PHP.
I'm using TYPO3 7.6.11
Your TypoScript is correct. However, since the rendering is delegated to a user-function the nested TypoScript properties are not executed - this has to happen in your custom user-function. The instance of ContentObjectRenderer
is automatically injected to your custom class as property PageIdByAlias::$cObj
.
<?php
namespace Vendor\Provider\UserFunc;
class PageIdByAlias
{
/**
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
*/
public $cObj;
protected $pageRepository;
/**
* Returns page ID by alias
*
* @var string $content
* @var array $configuration
* @return int|string
**/
public function getPageIdByAlias($content, array $configuration = null)
{
$pageId = 0;
// apply stdWrap() rendering for property 'alias'
// 3rd argument defines a custom default value if property is not set
$alias = $this->cObj->stdWrapValue('alias', $configuration, null);
if ($alias !== null) {
$pageId = $this->pageRepository->getPageIdByAlias($alias);
}
return $pageId;
}
}