Search code examples
typo3tx-indexed-search

There is no entry in the $TCA array for the table "index_stat_word". TYPO3, v.11.5. Indexed search


I need a help please. TYPO3 v.11.5. I'd like to get data from table index_stat_word (indexed_search):

page {
    10 = FLUIDTEMPLATE
    10 {
        dataProcessing {         
            20 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
            20 {
                table = index_stat_word
                select {
                    selectFields = word, COUNT(word) AS word_count
                    groupBy = word
                    orderBy = word_count DESC
                    max = 4
                }  
                as = mostPopularWords
            }
        }
    }
}

I have an error:

There is no entry in the $TCA array for the table "index_stat_word". This means that the function enableFields() is called with an invalid table name as argument.

The table "index_stat_word" is present and complete.

Thank you for the answers.


Solution

  • As Stefan Bürk commented please do not add TCA configuration and use a custom DataProcessor instead.

    Here is the documentation for that: https://docs.typo3.org/m/typo3/reference-typoscript/11.5/en-us/ContentObjects/Fluidtemplate/DataProcessing/CustomDataProcessors.html

    To achive want you want, you could implement following DataProcessor:

    <?php
    namespace VENDOR\ExtName\DataProcessing;
    
    use TYPO3\CMS\Core\Database\ConnectionPool;
    use TYPO3\CMS\Core\Utility\GeneralUtility;
    use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
    use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
    
    class IndexedStatWordProcessor implements DataProcessorInterface
    {
        /**
         * @param ContentObjectRenderer $cObj The data of the content element or page
         * @param array $contentObjectConfiguration The configuration of Content Object
         * @param array $processorConfiguration The configuration of this processor
         * @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
         *
         * @return array the processed data as key/value store
         */
        public function process(
            ContentObjectRenderer $cObj,
            array $contentObjectConfiguration,
            array $processorConfiguration,
            array $processedData
        ): array
        {
            $tableName = 'index_stat_word';
            $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
            $queryBuilder = $connectionPool->getQueryBuilderForTable($tableName);
            $result =  $queryBuilder->select('word')
                ->addSelectLiteral('COUNT(*) AS word_count')
                ->from($tableName)
                ->groupBy('word')
                ->orderBy('word_count', 'DESC')
                ->executeQuery()
                ->fetchAllAssociative();
    
            $processedData['data']['mostPopularWords'] = $result;
            // If you don't have other processed data in your template you could also do:
            //$processedData = [
            //    'mostPopularWords' => $result
            //];
            return $processedData;
    
        }
    }
    

    And then add it like that to your Typoscript:

    page {
      10 = FLUIDTEMPLATE
      10 {
        dataProcessing {
          20 = VENDOR\ExtName\DataProcessing\IndexedStatWordProcessor
        }
      }
    }