Reputation: 317
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
Upvotes: 2
Views: 5427
Reputation: 308
Try to use this in your user function
$pageId = $this->cObj->stdWrap($conf['page_id'], $conf['page_id.']);
after using this in typoscript
page_id.cObject = TEXT
page_id.cObject.data = GP:category
Upvotes: 1
Reputation: 4193
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;
}
}
Upvotes: 4
Reputation: 2249
Here is the solution working for me. Pass your argument with cObject from the html (from fluid or wherever you want).
<f:cObject typoscriptObjectPath="lib.categoryContent" >{category.uid}</f:cObject>
Or
<f:cObject typoscriptObjectPath="lib.categoryContent" data="{category.uid}" />
Typoscript :
# Set argument to the current.
lib.category = TEXT
lib.category{
current = 1
}
lib.categoryContent = USER
lib.categoryContent{
10 < styles.content.get
10 {
select {
pidInList.cObject = USER
pidInList.cObject {
userFunc = Vendor\Provider\UserFunc\PageIdByAlias->getPageIdByAlias
# Pass category id as argument
alias = TEXT
alias.value < lib.category
}
}
}
wrap = <categoryContent><![CDATA[|]]></categoryContent>
}
Upvotes: -2