phptypo3tt-newstypo3-extensions

Can't generate TYPO3 tt_news category tree for news entry



I'm using tt_news extension with my TYPO3 v7.6.18 (just upgraded from 6.2.31) and I'm having problems with category tree. I did a bit more debug for tt_news category rendering and this is the problem so far:

the old tca.php looks like this:

'category' => Array(
    'exclude' => 1,
    'label'   => 'LLL:EXT:tt_news/locallang_tca.xml:tt_news.category',
    'config'  => Array(
        'type'          => 'select',
        'form_type'     => 'user',
        'userFunc'      => 'tx_ttnews_TCAform_selectTree->renderCategoryFields',
        'treeView'      => 1,
        'foreign_table' => 'tt_news_cat',
        'autoSizeMax'   => 50,
        'minitems'      => $confArr['requireCategories'] ? 1 : 0,
        'maxitems'      => 500,
        'MM'            => 'tt_news_cat_mm',
    ),
),

And this gives me wrong results, meaning, I don't get a tree, but a multi select. Now, when I change type to user, I get this error:

Fatal error: Call to undefined method TYPO3\CMS\Backend\Form\Element\UserElement::addSelectOptionsToItemArray() in /home/portal/typo3project/typo3conf/ext/tt_news/lib/class.tx_ttnews_TCAform_selectTree.php on line 167

I checked the line in class tx_ttnews_TCAform_selectTree method renderCategoryFieldsand and it looks like this:

$selItems = $fobj->addSelectOptionsToItemArray($fobj->initItemArray($this->PA['fieldConf']),$this->PA['fieldConf'],$fobj->setTSconfig($table,$row),$field);

The $fobj comes as reference in function definition: function renderCategoryFields(&$PA, &$fobj) and it seems, that it is somewhere defined wrong, since addSelectOptionsToItemArray is located in FormEngine and not UserElement.

Since the method is called in the tca like tx_ttnews_TCAform_selectTree->renderCategoryFields I can't change class, it's using.

Any ideas how to fix this?


Solution

  • Since TYPO3 7 you don't need to define a custom user function to render a list as a tree. There is a renderType TCA configuration option for select-type fields, which can define tree rendering via selectTree value.

    So the configuration should look like follows:

    'category' => Array(
        'exclude' => 1,
        'label'   => 'LLL:EXT:tt_news/locallang_tca.xml:tt_news.category',
        'config'  => Array(
            'type'          => 'select',
            'renderType'    => 'selectTree',
            'foreign_table' => 'tt_news_cat',
            'autoSizeMax'   => 50,
            'minitems'      => $confArr['requireCategories'] ? 1 : 0,
            'maxitems'      => 500,
            'MM'            => 'tt_news_cat_mm',
            'treeConfig'    => array(
                'parentField' => 'parent_category',
            ),
        ),
    ),
    

    Additionally you may want to play with treeConfig configuration option for some visual tuning.