How set categorySelection a value of return of user funcion in Typoscript - typo3

I have a user function that return a list of categories (f.e. 20, 19) and I want to set in tt_news categorySelection as indicate the code
plugin.tt_news {
categorySelection = user_ttNewsCategoriesByUID
categoryMode = 2
}
Before of this I have the user function and works correctly
page.105 = USER
page.105 {
includeLibs = EXT:tt_news/Categorias.php
userFunc = user_ttNewsInCat
}
I am looking but I have not found something. How can I set the return of function in categorySelection

Since categorySelection is stdWrap enabled (see reference), you should be able to make use of it like this:
plugin.tt_news {
categorySelection >
categorySelection.cObject = USER
categorySelection.cObject.userFunc = user_ttNewsCategoriesByUID
categoryMode = 2
}

I found the answer and works correctly in this way
includeLibs.userCategories = EXT:tt_news/Categorias.php
temp.catuid = USER
temp.catuid.preUserFunc = user_ttNewsInCat
plugin.tt_news {
categorySelection < temp.catuid
categoryMode = 2
}

Related

TYPO3: Render a plugin via Typoscript or ViewHelper and change settings

I would like to load a plugin dynamically according to some data. First I tried to do it with Typoscript, but after some research I figured out, that it is not possible to change the settings of the plugin (see old forum entry).
I need to change settings.simplepoll.uid according to the passed data:
This is the Typoscript I tried:
lib.loadSimplepoll = USER
lib.loadSimplepoll {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
extensionName = Simplepoll
pluginName = Polllisting
vendorName = Pixelink
switchableControllerActions {
SimplePoll {
1 = list
}
}
settings < plugin.tx_simplepoll.settings
settings {
simplepoll {
uid.current = 1
}
}
}
The call in the template looks like that:
<f:cObject typoscriptObjectPath="lib.loadSimplepoll">{newsItem.simplepoll}</f:cObject>
After figuring out, that changing the settings is not possible, I tried a viewhelper:
<?php
namespace Vendor\Extension\ViewHelpers;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class LoadSimplepollViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
/**
* #param int $uid Uid of poll
* #return string
*/
public function render($uid) {
$cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
$configurationManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
$simplepollTs = $configurationManager->getConfiguration(
\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
'simplepoll',
'Polllisting'
);
$ttContentConfig = array(
'tables' => 'tt_content',
'source' => 1030,
'dontCheckPid' => 1
);
// returning this works perfectly!
// but I need to change the "settings.simplepoll.uid"
$data = $cObj->RECORDS($ttContentConfig);
$cObj->start($data, 'tx_simplepoll_domain_model_simplepoll');
$renderObjName = '<tt_content.list.20.simplepoll_polllisting';
$renderObjConf = $GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.']['simplepoll_polllisting.'];
$renderObjConf['persistence']['storagePid'] = 394; // This does not work!
$renderObjConf['settings'] = $simplepollTs;
$renderObjConf['settings']['simplepoll']['uid'] = $uid;
return $cObj->cObjGetSingle($renderObjName, $renderObjConf);
}
}
The viehelper is called like this:
{vh:LoadSimplepoll(uid: '{newsItem.simplepoll}')}
Now I am able to change the uid of the poll with this line:
$renderObjConf['settings']['simplepoll']['uid'] = $uid;
My problem is now, that it loads the poll, but not the answers. I tracked this down to the fact, that the plugin somehow does not know the Record Storage Page anymore. The line $renderObjConf['persistence']['storagePid'] = 394; does not help.
How can I tell the plugin the Storage Pid?
Or is there another/better way to load a plugin with changing data?
Why shouldn't it be possible to modify settings.simplepoll.uid in typoscript?
because the extension simplepoll does not handle any stdWrap functionality to its typoscript settings.
Have a look into the code:
this special setting is used here:
$simplePoll = $this->simplePollRepository->findByUid($this->settings['simplepoll']['uid']);
no stdWrap, just plain usage.
compare it to ext:news:
before any settings is used it is processed. A dedicated join of typoscript settings with the settings in the plugin. And if necessary there is a stdWrap possible: here
$this->originalSettings = $originalSettings;
// Use stdWrap for given defined settings
if (isset($originalSettings['useStdWrap']) && !empty($originalSettings['useStdWrap'])) {
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$typoScriptArray = $typoScriptService->convertPlainArrayToTypoScriptArray($originalSettings);
$stdWrapProperties = GeneralUtility::trimExplode(',', $originalSettings['useStdWrap'], true);
foreach ($stdWrapProperties as $key) {
if (is_array($typoScriptArray[$key . '.'])) {
$originalSettings[$key] = $this->configurationManager->getContentObject()->stdWrap(
$typoScriptArray[$key],
$typoScriptArray[$key . '.']
);
}
}
}
As you can see:
extbase does not support you with typoscript stdWrap functionality.
You (and every extension author) need to do it by hand. But that was so even before extbase.
In this way: as you can not configure your value you only can trick TYPO3 (and the plugin):
if you have a small number of uids you can have one variant for each uid
lib.loadSimplepoll123 < lib.loadSimplepoll
lib.loadSimplepoll123.settings.simplepoll.uid = 123
lib.loadSimplepoll234 < lib.loadSimplepoll
lib.loadSimplepoll234.settings.simplepoll.uid = 234
lib.loadSimplepoll345 < lib.loadSimplepoll
lib.loadSimplepoll345.settings.simplepoll.uid = 345
lib.loadSimplepoll456 < lib.loadSimplepoll
lib.loadSimplepoll456.settings.simplepoll.uid = 456
and call it like
<f:cObject typoscriptObjectPath="lib.loadSimplepoll{newsItem.simplepoll}" />
or you build a pull request implementing the stdWrap functionality and send it to the extension author.
Why shouldn't it be possible to modify settings.simplepoll.uid in typoscript?
you just need the correct construction to modify it.
For a single value you can use current, but use it properly. It is a stdWrap function which needs to be evaluated.
If there is no stdWrap evaluation by default it might work with a cObject of type TEXT
settings.simplepoll.uid.cObject = TEXT
settings.simplepoll.uid.cObject.current = 1
or to indicate a stdWrap you need to use stdWrap literally:
settings.simplepoll.uid.stdWrap.current = 1
another variant of data transfer are named parameters. Just build an associative array as data parameter and access the values individual:
fluid:
<f:cObject typoscriptObjectPath="lib.arraytest" data="{a:'abc',b:'xyz'}" >
inside text
</f:cObject>
and the typoscript:
lib.arraytest = COA
lib.arraytest {
10 = TEXT
10.field = a
10.wrap = /|/
20 = TEXT
20.field = b
20.wrap = \|\
}
which results in an output of /abc/\xyz\. Be aware: the inner text of the f:cobject tag will be lost as the data parameter has priority about inner children.
In the meantime I got the Viewhelpter to work:
Viewhelper:
<?php
namespace Vendor\Extension\ViewHelpers;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class LoadSimplepollViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{
/**
* #return void
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('simplepollUid', 'int', 'Uid of simplepoll', false);
}
/**
* #return string
*/
public function render()
{
$configurationManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
$simplepollTs = $configurationManager->getConfiguration(
\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
'simplepoll',
'Polllisting');
$cObj = GeneralUtility::makeInstance('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer');
$renderObjName = '<tt_content.list.20.simplepoll_polllisting';
$renderObjConf = $GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.']['simplepoll_polllisting.'];
$renderObjConf['settings'] = $simplepollTs;
$renderObjConf['settings']['simplepoll']['uid'] = (int)$this->arguments['simplepollUid'];
return $cObj->cObjGetSingle($renderObjName, $renderObjConf);
}
}
Call the viewhelper in the template (don't forget to register the namespace):
{vh:LoadSimplepoll(simplepollUid: '{newsItem.ipgSimplepoll}')}
That's it.

typolink userFunc in TYPO3 V8

I want to use the core linkhandler and change my link in a userFunc.
I use the linkhandler as it is described here, and it works with a single detail page:
https://usetypo3.com/linkhandler.html
The problem is:
If i change my typoscript to:
config.recordLinks {
tx_news {
typolink {
userFunc = Vendor\Name\UserFunc\TypolinkUserFunc->parseLinkHandlerTypolink
userFunc {
newsUid = TEXT
newsUid.data = field:uid
newsClass = TEXT
newsClass.data = parameters:class
defaultDetailPid = 53
}
}
}
}
it doesn't work.
I cannot address the userFunc. I'm in an extension. i use
'autoload' =>
array(
'psr-4' => array('Vendor\\Name\\' => 'Classes')
),
);
in order to load my userFunc Class.
I do not get any error message.
You must have figured it out by now, but you have to run a userFunc as USER.
10 = USER
10 {
userFunc = TYPO3\Extension\Sample->user_exampleUserFunc
}
So as a sample, your code should look something like this:
config.recordLinks {
tx_news {
typolink {
10 = USER
10 {
userFunc = Vendor\Name\UserFunc\TypolinkUserFunc->parseLinkHandlerTypolink
userFunc {
newsUid = TEXT
newsUid.data = field:uid
newsClass = TEXT
newsClass.data = parameters:class
defaultDetailPid = 53
}
}
}
}
}
As the above is just an example, it should get you started.

How to communicate two plugins of News for Typoscript

I have to show in my single page: the single and the list of News with the same categories of single new. I have two plugins in my backend page and have tried to assign the categories of single to the list for typoscript, but i could not do it.
This is the code, i used page.x for debug and catch values:
page.100 = TEXT
page.100.data = GP:tx_ttnews|tt_news
page.100.wrap = The single tt_news id is: |
page.100.data = GP:tx_ttnews|cat
page.100.wrap = The category of single is: |
page.110 = TEXT
page.110
{
value = { register:newsCategoryUid }
insertData = 1
wrap = - Categories: |
}
plugin.tt_news
{
categorySelection = { register:newsCategoryUid }
#show only selected categories
categoryMode = 1
}
It's not fully visible what you're trying. I think the best way should to put the cat value inside a temp object. Do you have the plugins inserted by TypoScript or as Content Element? You are using tt_news not news by georg ringer right?
temp.tx_news_catId = TEXT
temp.tx_news_catId.data = GP:tx_ttnews|cat
temp.tx_news_catId.intval = 1
page.110 < temp.tx_news_catId
page.110.wrap = Category: |
plugin.tt_news
{
categorySelection < temp.tx_news_catId
# you need to use data not categorySelection = {...} <- that should
# only work on constants
# but only works if categorySelection capabilities
#categorySelection.data = register:newsCategoryUid
#show only selected categories
categoryMode = 1
}
(Untested TypoScript)
hope this helps you a little bit
PS: Have you checked whether categorySelection has stdWrap capabilities?
I don't really get what you want to do, maybe this helps a bit:
If you want to show in the detail action articles with the same category as the current one, you can use a snippet like this one:
Add this to the Detail.html which will pass the first category uid to the TypoScript object lib.tx_news.relatedByFirstCategory.
<f:if condition="{newsItem.firstCategory}">
<f:cObject typoscriptObjectPath="lib.tx_news.relatedByFirstCategory">{newsItem.firstCategory.uid}</f:cObject>
</f:if>
and the TS:
lib.tx_news.relatedByFirstCategory = USER
lib.tx_news.relatedByFirstCategory {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
extensionName = News
pluginName = Pi1
vendorName = GeorgRinger
switchableControllerActions {
News {
1 = list
}
}
settings < plugin.tx_news.settings
settings {
relatedView = 1
detailPid = 31
useStdWrap := addToList(categories)
categories.current = 1
categoryConjunction = or
overrideFlexformSettingsIfEmpty := addToList(detailPid)
startingpoint = 78
}
}
I have taken this from the manual.

typoscript issue with LOAD_REGISTER and if condition to fill a list

What I'm trying to do is quite complex and an Extbase extension is involved...
Step by step, what I'm trying to do:
An Extbase plugin decides, if certain navigation elements should be marked.
This plugin has one action for each navigation element.
The returned value (0 or 1) from each action in TS is stored on the stack (LOAD_REGISTER).
A list of page UIDs is build by checking against the stored values (0,1).
The navigation COA is modified using this list of page UIDs.
Here is the typoscript code I'm using:
// load information, if pages lack info, into register
10 = LOAD_REGISTER
10 {
lacksAnfahrt {
cObject = USER_INT
cObject {
userFunc = tx_extbase_core_bootstrap->run
pluginName = Pa_klinik_data_edit
extensionName = Hplusinfo
controller = SpitalInfoPA
switchableControllerActions {
SpitalInfoPA {
1 = completeAnfahrt
}
}
}
}
lacksAktivitaeten < .lacksAnfahrt
lacksAktivitaeten.cObject.switchableControllerActions.SpitalInfoPA.1 = completeAktivitaeten
lacksBildergalerie < .lacksAnfahrt
lacksBildergalerie.cObject.switchableControllerActions.SpitalInfoPA.1 = completeBildergalerie
// build a list of PIDs that are going to be marked in navigation
lackPIDs.cObject = COA
lackPIDs.cObject {
10 = TEXT
10 {
value = {$config.PIDLists.anfahrt},
if {
value = 1
equals.data = register:lacksAnfahrt
}
}
20 < .10
20.value = {$config.PIDLists.bildergalerie},
20.if.equals.data = register:lacksBildergalerie
30 < .10
30.value = {$config.PIDLists.aktivitaeten},
30.if.equals.data = register:lacksAktivitaeten
// don't let the comma separated list end with a comma
99 = TEXT
99.value = 0
} // lackPIDs
} // REGISTER
// mark incomplete pages with a red exclamation mark
20 { // = HMENU
1 { // = TMENU
NO { // = 1
stdWrap.wrap = |<span class="warning lacksInfo">!</span>
stdWrap.wrap.if {
value.data = register:lackPIDs
isInList.field = uid
}
}
}
}
If i print out register:lacksBildergalerie and all the others, their values are correct (0 or 1).
But the lackPIDslist always empty (except of the 0 at the end)... There must be something wrong with the middle part:
10 {
value = {$nav.PIDLists.anfahrt},
if {
value = 1
equals.data = register:lacksAnfahrt
}
}
This evaluation seams to return false in any case.
I also tried with different if function like:
10 {
value = {$nav.PIDLists.anfahrt},
if {
isTrue.data = register:lacksAnfahrt
}
}
But this doesn't solve the problem.
Just overlooked that the other registers are using USER_INT as well

Set templavoila template with typoscript

Is it possible to set a page's templavoila template with typoscript?
I have solved it with:
includeLibs.lang = fileadmin/user_tvtest.php
page.1 = USER_INT
page.1.userFunc = user_tvtest->main
page.10 = USER_INT
page.10.userFunc = tx_templavoila_pi1->main_page
page.10.disableExplosivePreview = 1
and in fileadmin/user_tvtest.php:
class user_tvtest
{
function main($content, $conf)
{
if (is_mobile())
{
$GLOBALS['TSFE']->page['tx_templavoila_to'] = 7;
//$GLOBALS['TSFE']->page['tx_templavoila_ds'] = 7;
}
}
}
http://daschmi.de/templavoila-template-domainbezogen-umschalten-gleicher-seitenbaum/
Look how the page is configured by TemplaVoila:
page = PAGE
page.typeNum = 0
page.10 = USER
page.10.userFunc = tx_templavoila_pi1->main_page
page.shortcutIcon = {$faviconPath}
They call the main_page function of class tx_templavoila_pi1 via page.userFunc:
/**
* Main function for rendering of Page Templates of TemplaVoila
*
* #param string Standard content input. Ignore.
* #param array TypoScript array for the plugin.
* #return string HTML content for the Page Template elements.
*/
function main_page($content,$conf) {
$this->initVars($conf);
// Current page record which we MIGHT manipulate a little:
$pageRecord = $GLOBALS['TSFE']->page;
// Find DS and Template in root line IF there is no Data Structure set for the current page:
if (!$pageRecord['tx_templavoila_ds']) {
foreach($GLOBALS['TSFE']->tmpl->rootLine as $pRec) {
if ($pageRecord['uid'] != $pRec['uid']) {
if ($pRec['tx_templavoila_next_ds']) { // If there is a next-level DS:
$pageRecord['tx_templavoila_ds'] = $pRec['tx_templavoila_next_ds'];
$pageRecord['tx_templavoila_to'] = $pRec['tx_templavoila_next_to'];
} elseif ($pRec['tx_templavoila_ds']) { // Otherwise try the NORMAL DS:
$pageRecord['tx_templavoila_ds'] = $pRec['tx_templavoila_ds'];
$pageRecord['tx_templavoila_to'] = $pRec['tx_templavoila_to'];
}
} else break;
}
}
// "Show content from this page instead" support. Note: using current DS/TO!
if ($pageRecord['content_from_pid']) {
$ds = $pageRecord['tx_templavoila_ds'];
$to = $pageRecord['tx_templavoila_to'];
$pageRecord = $GLOBALS['TSFE']->sys_page->getPage($pageRecord['content_from_pid']);
$pageRecord['tx_templavoila_ds'] = $ds;
$pageRecord['tx_templavoila_to'] = $to;
}
return $this->renderElement($pageRecord, 'pages');
}
This function checks the current page or search trough the rootline (TSFE) for the configured page template. The script does not check any TypoScript settings at all so I suppose thats not supported by TemplaVoila right now.
It should not be too hard extending this class with a custom function that will check some TypoScript settings.