My page doesn't recognize my Extbase plugin Controller

50 views Asked by At

I am trying to add a plugin to my extension using Extbase.

I am able to add the plugin in the backend interface, but adding it does not take effect, and the controller is not recognized and am getting blank page (I activated debugg in TypoScript and PHP).

I creatted the following (i tooked out the namespace )

in cars/ext_localconf.php

    ExtensionUtility::configurePlugin(
    'Cars',
    'Show',
    [
        CarController::class => 'list, show'
    ]
);

in cars/Configuration/TCA/Overrides/tt_content.php

ExtensionUtility::registerPlugin(
'Cars',
'Show',
'List Cars'
);

I also added the TypoScript file using sys_template.php, and than included as static file

in cars/Configuration/TypoScript

page = PAGE
page.typeNum = 0
page.config.contentObjectExceptionHandler = 0

plugin.tx_cars {
    view {
        templateRootPaths {
            0 = EXT:cars/Resources/Private/Templates/
        }

        partialRootPaths {
            0 = EXT:cars/Resources/Private/Partials/
        }

        layoutRootPaths {
            0 = EXT:cars/Resources/Private/Layouts/
        }
    }

    settings {
        singleViewPageUid = 4
    }
}

in cars/Classes/Controller/CarController.php

class CarController extends AbstractController
{


    public function listAction(): ResponseInterface
      {
          return $this->htmlResponse('<h1>Hello World!</h1>');
      }

      public function showAction()
      {

      }
}

There is also Model and Repository it is hard to put everything. You can see the extension in this GitHub repository, which has a very simple structure. github repository

I believe the problem came from TypoScript, as I am not able to understand how to add the plugin in TypoScript. Am I right? Did I miss something else?

1

There are 1 answers

2
David On

The namespace is missing in ext_localconf.php and Configuration/TCA/Overrides/tt_content.php. Furthermore there is no need to configure it in both files, usually it's done only in ext_localconf.php.

ext_localconf.php:

ExtensionUtility::configurePlugin(
    'Cars',
    'Show',
    [
        \VENDOR\EXTENSIONNAME\CarController::class => 'list, show'
    ]
);

VENDOR and EXTENSIONNAME have to be replaced by your individual values.

Another requirement is to include the static TypoScript in the root Template record. This can be also indirectly in a sitepackage where you include the extension file.
In latter case you've to care though that you include the file constants.typoscript of the cars extension in the constants.typoscript of the sitepackage and the file setup.typoscript of the cars extension in the setup.typoscript of the sitepackage.

I'm not sure if this solves your issues, but that would be the first step.

Another approach would be to create your extension with the extension_builder but then you should use TYPO3 v11. Actually I can't promise that it's working flawless there but in v12 it's still not advisable at all, especially for beginners.

EDIT: Another important step is to configure the storagePid in the TypoScript with the value where the car-records are resided. Else the output stays empty or shows only general template parts without data.