Search code examples
typo3typo3-9.x

How to add custom wizards in TYPO3 9 TCA?


Related to How to add custom wizards in typo3 7 TCA? how can costum wizards in TYPO3 9 be implemented? I've added my entry to the Routes.php

return [
    'tx_csseo_preview' => [
        'path' => '/wizard/tx_csseo/preview',
        'target' => \Clickstorm\CsSeo\UserFunc\PreviewWizard::class . '::render'
    ],
    'tx_csseo_permalink' => [
        'path' => '/wizard/tx_csseo/permalink',
        'target' => \Clickstorm\CsSeo\UserFunc\PermalinkWizard::class . '::render'
    ]
];

How can I add them now to my TCA field?

'tx_csseo_title' => [
        'label' => 'LLL:EXT:cs_seo/Resources/Private/Language/locallang_db.xlf:pages.tx_csseo_title',
        'exclude' => 1,
        'config' => [
            'type' => 'input',
            'max' => $extConf['maxTitle'],
            'eval' => 'trim',
            'fieldWizard' => [
                'tx_csseo_preview' => [
                    'disabled' => false,
                ]
            ]
        ]
    ],

This does not work. What do I miss? Thanks in advance.


Solution

  • Related to your kind of wizard the registration-process is different and extensive explained here. You can leave the entries in Routes.php away (perhaps even the whole file if nothing else is inside).

    Registration is done in ext_localconf.php:

    $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1485351217] = [
       'nodeName' => 'importDataControl',
       'priority' => 30,
       'class' => \T3G\Something\FormEngine\FieldControl\ImportDataControl::class
    ];
    

    Then reference the new wizard in TCA:

    'somefield' => [
       'label'   => $langFile . ':pages.somefield',
       'config'  => [
          'type' => 'input',
          'eval' => 'int, unique',
          'fieldControl' => [
             'importControl' => [
                'renderType' => 'importDataControl'
             ]
          ]
       ]
    ],
    

    Then finally the class with the "magic"

    declare(strict_types=1);
    
    namespace T3G\Something\FormEngine\FieldControl;
    
    use TYPO3\CMS\Backend\Form\AbstractNode;
    
    class ImportDataControl extends AbstractNode
    {
       public function render()
       {
          $result = [
             'iconIdentifier' => 'import-data',
             'title' => $GLOBALS['LANG']->sL('LLL:EXT:something/Resources/Private/Language/locallang_db.xlf:pages.importData'),
             'linkAttributes' => [
                'class' => 'importData ',
                'data-id' => $this->data['databaseRow']['somefield']
             ],
             'requireJsModules' => ['TYPO3/CMS/Something/ImportData'],
          ];
          return $result;
       }
    }
    

    In the linked example there is still an Ajax Route with corresponding files, including a special defined route, but that's not required to get the basic wizard shown.

    Concerning the registration in ext_localconf.php there is above the number 1485351217 as array-key shown. For an own registered node just calculate once the current time as unix-timestamp and enter that instead. So it's unique and can't be mistaken with other definitions of any registered nodes.

    In contrast to the linked example I used slightly different descriptions, so I call the process in ext_localconf.php registering, and the inclusion in TCA referencing. Perhaps this small difference makes it a bit more clear.

    Icons

    Concerning Icons there is still a difference to earlier TYPO3 versions, they have to be registered now too and in TCA they are only referenced too by the registered name. Here in the TCA-file is no icon referenced but the class below makes usage of it. Here is an example how an icon has to be registered in ext_tables.php:

    $systemIconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
    $systemIconRegistry->registerIcon(
        'imagemapwizard_link_edit',
        \TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider::class,
        [
            'source' => 'EXT:imagemap_wizard/Resources/Public/Icons/link_edit.png'
        ]
    );
    

    The new icon registry is implemented starting with TYPO3 version 7.5