John Miller
John Miller

Reputation: 717

How to call extbase action from TypoScript

This question has been asked and answered numerous times through blogs and other platforms on the internet. However, the solutions don't seem to work for TYPO3 version 10 (I think also for versions 7, 8 and 9).

I have a class SpaceController with action shuttleAction which are well registered and uncached in ext_localconf.php file.

Here's what I've tried:

10 = USER_INT
10 {
    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
    extensionName = Navigator
    pluginName = mission
    vendorName = Orbit

    switchableControllerActions {
        Space{
            1 = shuttle
        }
    }
}

I get the error;

(1/2) #1278450972 TYPO3\CMS\Extbase\Reflection\Exception\UnknownClassException
Class does not exist. Reflection failed.

The class, plugin, extension and vendor do exist and in fact am using them for other actions, which work. However, can't get to pick an action via typoscript from the class.

I've tried the same with other Controllers and actions but none seems to work with this method.

Am trying to execute an action via TypoScript. How do I call a Controller's action from TypoScript? Am using TYPO3 version 10. I believe methods for versions 8 or 9 can also work for version 10. I've tried the same with these versions to no avail.

The following method works, but picks the first (default) action.

10 = USER
10 {

    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
    vendorName = Orbit
    extensionName = Navigator
    pluginName = mission
}

If I add controller and action, action gets ignored in favor of default action.

10 = USER
10 {

    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
    vendorName = Orbit
    extensionName = Navigator
    pluginName = mission
    controller = Space
    action = shuttle
}

I would like to pick the specific action to execute.

Upvotes: 3

Views: 2280

Answers (1)

John Miller
John Miller

Reputation: 717

After hours of searching and experiments, it is clear that it's not possible at the moment to select an action via TypoScript. However, there is a workaround.

For anyone looking for a solution to this problem,

  1. Create a new plugin entry in your ext_localconf.php for the controller and action you want.
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'yourExtension',
    'yourPlugin1',
    [
        'FooController' => 'list'
    ]
);

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
    'yourExtension',
    'yourPlugin2',
    [
        'FooController' => 'show'
    ]
);
  1. Make sure the action you want is the first (default) one in the list. If you put more then one action in one plugin and you will try to execute any other then first from TypoScript it won't work.
  2. Reference that plugin in your TypoScript.

Hope it helps someone.

Anyone with a better solution is welcome to provide it or improve this one.

Upvotes: 6

Related Questions