Contao 4.13: Cannot access system module from Bundle

62 Views Asked by At

We are porting a Contao 4.3 installation to 4.13 and a part of it is already in a bundle.

In our Controller in the bundle we have code like this:

use foo_events\Foo_Payment;

class ApplicationController

    public function notifypaypalAction()
    {
        $arrConfig = Foo_Payment::getConfig('paypal');
    }

Now the Foo_Payment class cannot be found. It is in the module autoload.php but it seems like in the bundle Contao is not properly initialized.

Can we still load old modules in a bundle or do we have to port everything to the bundle?

I already tried to

require_once '../../../system/modules/foo_events/classes/Foo_Payment.php';

This solves the Problem with finding Foo_Payment, but the code

        return $GLOBALS['TL_CONFIG']['fooevents']['giropay'][$strConfigType][$strEnv];

now crashes with

Warning: Undefined global variable $TL_CONFIG

while I would expect TL_CONFIG to be always accessible.

1

There are 1 best solutions below

0
Alex On
  1. I Implemented implements \Symfony\Component\DependencyInjection\ContainerAwareInterface
  2. I added
public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }
  1. I added
    protected function initializeContao()
    {
        // added manually because we could not extend \Contao\CoreBundle\Controller\AbstractController,
        // because this would cause problems with the previous container setting in
        // @see \Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver::instantiateController

        $this->container->get('contao.framework')->initialize();
    }
  1. I called this method