flux icon indicating copy to clipboard operation
flux copied to clipboard

PageController not intialiased

Open deivibub opened this issue 4 years ago • 4 comments

Hi there,

I'm using TYPO3 10.4.9 with flux 9.4.2 and registered the controllers

if(class_exists(\FluidTYPO3\Flux\Core::class)){
  \FluidTYPO3\Flux\Core::registerProviderExtensionKey('Oyc.OycTemplate', 'Content');
  \FluidTYPO3\Flux\Core::registerProviderExtensionKey('Oyc.OycTemplate', 'Page');
}

ContentController actions get invoked corresponding to the names of the template files, but having a page template with the name "Standard.html" an action called "standardAction" never gets invoked.

Am I missing something here?

Thank you

deivibub avatar Nov 06 '20 13:11 deivibub

Class loading may be incorrectly configured, your PageController's namespace may be incorrect (case sensitivity may apply) or there may be a typo in the class name or file. You should be able to check this by debugging class_exists($yourPageControllerClassName) somewhere else, which would verify if class loading works.

NamelessCoder avatar Nov 06 '20 14:11 NamelessCoder

Thank you @NamelessCoder

I checked inside an action of the ContentController and it returned true.

I'm using my provider since flux version 8.2.1 with fluidcontent and fluidpages installed as well (that time). Could there be a migration issue, something I've overseen?

Thank you

deivibub avatar Nov 07 '20 15:11 deivibub

I've also experienced some problems. I also noticed neither the "myAction" nor the "initializeAction" methods are invoked. But if you simply need to add some Variables, try overriding like this:

<?php
namespace TYPOworx\FooBar\Controller;

use FluidTYPO3\Flux\Controller\PageController as FluxPageController;

/**
 * Class PageController
 * @package TYPOworx\FooBar\Controller
 * @route off
 */
class PageController extends FluxPageController
{
    use ContentDataProcessorTrait;

    protected function initializeViewVariables()
    {
        parent::initializeViewVariables();
        this->view->assign('foo', 'bar'); // modify to your needs
    }
}

typoworx-de avatar Jan 06 '21 23:01 typoworx-de

I think this problem was solved with commit https://github.com/FluidTYPO3/flux/commit/19279684f1792f373d3a1fafdbde4dea0e4e12d9 (currently only in the development branch) - but it would be great if you could confirm!

Side note: if you need specific variables within your templates this can also be done by creating a ViewHelper that reads the variables and assigns them into the VariableProvider via RenderingContext, e.g.:

$renderingContext->getVariableProvider()->add('myvariable', 'myvalue');

Or if a ViewHelper already exists which returns the right variable, the output of such a ViewHelper can be assigned as a template variable through this Fluid syntax:

{my:variableViewHelper() -> f:variable(name: 'myvariable')}

NamelessCoder avatar Dec 05 '21 13:12 NamelessCoder

Closing as "part unexplained, part solved, part by-design and has workarounds".

For anyone interested:

  • \FluidTYPO3\Flux\Controller\AbstractFluxController::performSubRendering contains the business logic that detects if a custom controller should be called.
  • \FluidTYPO3\Flux\Controller\AbstractFluxController::callSubControllerAction invokes the action method on the custom controller, if it exists.
  • \TYPO3\CMS\Extbase\Mvc\Controller\ActionController::processRequest is called to render the action on the controller, which is the same way a vanilla controller would be executed - this method should trigger any custom initialize* methods that your controller contains but note that the composition of this method differes slightly on the supported versions of TYPO3. The short version is: anything that works in a vanilla controller in terms of initialize methods should work identically in a Flux-enabled controller.

NamelessCoder avatar Nov 07 '22 14:11 NamelessCoder