Search code examples
typo3typoscript

TYPO3 TypoScript How to pass current element identifier to userFunc


We are indexing events into our Solr cores. Now we need additional data which we cannot generate when events are created so we need to process the events before indexing to fill a new field.

To do the necessary processing in the userFunc we would need at least an identifier from the current element getting indexed.

So here is the config, stripped down:

plugin.tx_solr.index.queue {
    events = 1
    events {
        table = tx_events_domain_model_event

        fields { 

            # this is the new field
            eventTopicNames_textEdgeNgramM = SOLR_MULTIVALUE
            eventTopicNames_textEdgeNgramM {
                stdWrap.cObject = USER
                stdWrap.cObject.userFunc = XXX\xxxevents\Helper\EventTopicNamesHelper->getValues
                stdWrap.cObject.userFunc {
                    internalTopics = field:uid
                    uid.data = current:identifier
                }
                separator=,
            }

            # ... alot of other fields

        }

So here I'm trying to call my userFunc to process the topic names for the given event - but I was not able to find out how I can pass the actual identifier of the current element to my userFunc. I can pass data in general, for example some hardcoded string like internalTopics = "foobar" works without issues.

I tried

  • current:uid
  • current:identifier
  • field:uid

But nothing gets actually parsed to the value we need - instead the output is just the corresponding string value like "current:uid" and so on ...

Here is the little helper class:

class EventTopicNamesHelper
{
    public function getValues($content = '', $conf = array()) {
      // $conf['userFunc.']['internalTopics'] 

      // ... returning values suitable for SOLR_MULTIVALUE
    }
}

Help is much appreciated


Solution

  • Properties of userFunc are just passed to the function, but there is no stdWrap-functionality applied before passing. So your userFunc is getting the raw TS array/values, and your function has to interpret the TypoScript itself.

    For this, you need a ContentObjectRenderer-object and the name of your property:

    $internalTopics = $this->cObj->cObjGetSingle(
        $config['internalTopics'], 
        $config['internalTopics.']
    );