1

Context

I try to find a way to integrate Webpack Encore into Drupal. Since we can't use Symfony Bundles in Drupal I want to port the bundle to a custom Drupal module.

What I have done so far

To register an alter services I use a custom compiler pass described here

So my Service Provider looks like that:

class WebpackEncoreServiceProvider extends ServiceProviderBase
{
    /**
     * {@inheritdoc}
     */
    public function register(ContainerBuilder $container) {
        $container->addCompilerPass(new WebpackEncoreExtensionPass());
    }
}

My custom extension pass looks like that:

class WebpackEncoreExtensionPass implements CompilerPassInterface
{
    /**
     * {@inheritdoc}
     */
    public function process(ContainerBuilder $container)
    {
        //get the parameters from mymodule.services.yml
        $configs = Yaml::parseFile(\dirname(__DIR__).'/../webpack_encore.services.yml');
        $config = $configs['parameters']['webpack_encore'];
        // Drupal does not load configs from files like Symfony does.
        $container->prependExtensionConfig('webpack_encore', ['output_path' => $config['output_path']]);
        $extension = new WebpackEncoreExtension();
        $extension->load([$config], $container);
        $container->registerExtension($extension);
        $container->loadFromExtension($extension->getAlias());
//      var_dump($container->getDefinitions());die();
        $container->compile();
    }
}

Problem

The container is not build a states that there are missing proxy classes. This output is from the browser and it runs in circles:

User warning: Missing proxy class 'Symfony\Component\ProxyClass\HttpKernel\HttpKernel' for lazy service 'http_kernel.basic'. Use the following command to generate the proxy class: php core/scripts/generate-proxy-class.php 'Symfony\Component\HttpKernel\HttpKernel' "[namespace_root_path]" in Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass->process() (line 61 of /var/www/html/mws_bundles/dietpet.vet/web/core/lib/Drupal/Core/DependencyInjection/Compiler/ProxyServicesPass.php).
Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass->process(Object) (Line: 94)
Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object) (Line: 762)
Symfony\Component\DependencyInjection\ContainerBuilder->compile() (Line: 34)
Drupal\webpack_encore\Compiler\WebpackEncoreExtensionPass->process(Object) (Line: 94)
Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object) (Line: 762)
Symfony\Component\DependencyInjection\ContainerBuilder->compile() (Line: 1293)
Drupal\Core\DrupalKernel->compileContainer() (Line: 898)
Drupal\Core\DrupalKernel->initializeContainer() (Line: 471)
Drupal\Core\DrupalKernel->boot() (Line: 705)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
User warning: Missing proxy class 'Drupal\Core\ProxyClass\StackMiddleware\KernelPreHandle' for lazy service 'http_middleware.kernel_pre_handle'. Use the following command to generate the proxy class: php core/scripts/generate-proxy-class.php 'Drupal\Core\StackMiddleware\KernelPreHandle' "core/lib/Drupal/Core" in Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass->process() (line 61 of /var/www/html/mws_bundles/dietpet.vet/web/core/lib/Drupal/Core/DependencyInjection/Compiler/ProxyServicesPass.php).
Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass->process(Object) (Line: 94)
Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object) (Line: 762)
Symfony\Component\DependencyInjection\ContainerBuilder->compile() (Line: 34)
Drupal\webpack_encore\Compiler\WebpackEncoreExtensionPass->process(Object) (Line: 94)
Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object) (Line: 762)
Symfony\Component\DependencyInjection\ContainerBuilder->compile() (Line: 1293)
Drupal\Core\DrupalKernel->compileContainer() (Line: 898)
Drupal\Core\DrupalKernel->initializeContainer() (Line: 471)
Drupal\Core\DrupalKernel->boot() (Line: 705)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
User warning: Missing proxy class 'Drupal\Core\ProxyClass\StackMiddleware\Session' for lazy service 'http_middleware.session'. Use the following command to generate the proxy class: php core/scripts/generate-proxy-class.php 'Drupal\Core\StackMiddleware\Session' "core/lib/Drupal/Core" in Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass->process() (line 61 of /var/www/html/mws_bundles/dietpet.vet/web/core/lib/Drupal/Core/DependencyInjection/Compiler/ProxyServicesPass.php).
Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass->process(Object) (Line: 94)
Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object) (Line: 762)
Symfony\Component\DependencyInjection\ContainerBuilder->compile() (Line: 34)
Drupal\webpack_encore\Compiler\WebpackEncoreExtensionPass->process(Object) (Line: 94)
Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object) (Line: 762)
Symfony\Component\DependencyInjection\ContainerBuilder->compile() (Line: 1293)
Drupal\Core\DrupalKernel->compileContainer() (Line: 898)
Drupal\Core\DrupalKernel->initializeContainer() (Line: 471)
Drupal\Core\DrupalKernel->boot() (Line: 705)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I tried the commands mentioned on the console but this also runs in circles and does not generate the proxy classes.

What I wonder is this command:

php core/scripts/generate-proxy-class.php 'Symfony\Component\HttpKernel\HttpKernel' "[namespace_root_path]"

Shouldn't there be a real path?

How can I solve this problem?

Should this be considered a bug? If yes where can I file a bug report?

1 Answer 1

0

I found the answer. I had to remove $container->compile(); cause this is done by drupal in a later step.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.