4


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?

Peon
  • 7,902
  • 7
  • 59
  • 100

1 Answers1

3

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.

Viktor Livakivskyi
  • 3,178
  • 1
  • 21
  • 33
  • In addition you may simply update `tt_news` to the latest version, because it claims to be compatible with TYPO3 7.x. – Viktor Livakivskyi May 31 '17 at 12:51
  • I already tried this. It produces the `#1288215890: TCA Tree configuration is invalid: "treeConfig" array is missing` error. And when I add the `'treeConfig' => array( 'expandAll' => true, 'parentField' => 'pid', 'appearance' => array( 'showHeader' => TRUE, ), ),` I get zero categories or, if I change the `parentField` to 0 I get all categories in one single branch and a huge mess (since names overlapp). – Peon May 31 '17 at 13:29
  • @DainisAbols you can compare your TCA with TCA form [tt_news 7.6.3](https://github.com/rupertgermann/tt_news/blob/7.6.3/Configuration/TCA/tt_news.php#L339-L361). Probably, the issue can be solved by adding `'parentField' => 'parent_category',` in `treeConfig` section. – Viktor Livakivskyi May 31 '17 at 13:44
  • Thank you, `parent_category` seems promising on first tests, will let you know tomorrow morning. For now workday is already 2h overdue. – Peon May 31 '17 at 14:06
  • @DainisAbols nice, I've updated my code example in the answer to reflect this change. – Viktor Livakivskyi May 31 '17 at 14:17
  • I took the new TCA from `tt_news` repository. Now I get the tree correct, but it doesn't read the old selects (the new ones work fine). I see that the new TCA also uses `'dataProvider' => \WMDB\TtNews\Tree\TableConfiguration\NewsDatabaseTreeDataProvider::class,` what I don't have. Any ideas about that one? – Peon May 31 '17 at 14:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/145628/discussion-between-viktor-livakivskyi-and-dainis-abols). – Viktor Livakivskyi Jun 01 '17 at 12:05