This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » Registering bundles depending on...
expandshrink

Registering bundles depending on siteaccess

Registering bundles depending on siteaccess

Wednesday 20 August 2014 10:58:30 am - 1 reply

Goal

There is a need to choose which bundles to load depending on site group access. Example for site group "website1" and "website2".

case 'website1':    
$bundles[] = new EshopBundle();    
$bundles[] = new Project\Website1Bundle\ProjectWebsite1Bundle();    
break;
case 'website2':    
$bundles[] = new EshopBundle();    
$bundles[] = new Project\Website2Bundle\ProjectWebsite2Bundle();    
break;

Also we need to remove loading yml files from imports in ezpublish/config.yml. Only the one for registered bundles should be loaded.

imports:    
- { resource: parameters.yml }    
- { resource: security.yml }    
- { resource: "@EshopBundle/Resources/config/eshop.yml" }    
#- { resource: "@ProjectWebsite1Bundle/Resources/config/parameters.yml" }    
#- { resource: "@ProjectWebsite1Bundle/Resources/config/services.xml" }    
#- { resource: "@ProjectWebsite2Bundle/Resources/config/parameters.yml" }    
#- { resource: "@ProjectWebsite2Bundle/Resources/config/services.xml" }

Important: ProjectWebsite1Bundle and ProjectWebsite2Bundle are extending EshopBundle 

Kernel Configuration for site accesses

There is a class that handles registering bundles depending on site group. It adds proper bundles and it works fine.

EzPublishKernel.php -> registerBundles()

$ourKernel = new OurKernel($this->getEnvironment());
$addBundles = $ourKernel->getAddDomainBundles();
$bundles = array_merge($bundles, $addBundles);
return $bundles;

SOLUTION 1 - DependencyInjection using Extensions

We tried using Extensions to add configuration with DependencyInjection Compiler

Example for ProjectWebsite1Extension : 

class ProjectWebsite1Extension extends Extension{   
/**     * {@inheritDoc}     */    
public function load(array $configs, ContainerBuilder $container)    { 
  $configuration = new Configuration();        
  $config = $this->processConfiguration($configuration, $configs);           

$loader = new Loader\XmlFileLoader($container, 
new FileLocator(__DIR__.'/../Resources/config'));        
$loader->load('services.xml');        

$loader = new Loader\YamlFileLoader($container,
new FileLocator(__DIR__.'/../Resources/config'));       
$loader->load('parameters.yml');
}
}

Problems 

In our project we want to override parameters which are already in eshop.yml.

Example: We have "eshop.data_provider" in eshop.yml and it is imported from config.yml. We want to override it in ProjectWebsite1Bundle (exactly the same name of parameter).

Problem is that compiler cannot override existing parameters once the container is build, because of implementation of MergeExtensionConfigurationPass.php

SOLUTION 2 - Modifying Kernel

Next solution we tried was adding imports in Kernel before container is build.

public function registerContainerConfiguration( LoaderInterface $loader )    {        $environment = $this->getEnvironment();        $loader->load( __DIR__ . '/config/config_' . $environment . '.yml' );        $configFile = __DIR__ . '/config/ezpublish_' . $environment . '.yml';        if ( !is_file( $configFile ) )        {            $configFile = __DIR__ . '/config/ezpublish_setup.yml';        }        if ( !is_readable( $configFile ) )        {            throw new RuntimeException( "Configuration file '$configFile' is not readable." );        }        $loader->load( $configFile );        $ourKernel = new OurKernel($this->getEnvironment());        $addImports = $ourKernel ->getAddImports();        foreach($addImports as $import) {            $loader->load( $import );        }    }

Problems

This solution overrides the parameters, but when we want to access the page overriding templates does not work. All templates are taken from EshopBundle instead of ProjectWebsite1Bundle. It looks like general idea behind symfony that files from vendor are overriden by those in src folder is not working.

 

If anyone had that kind of problem please share.

Best regards,

Tomasz Jasek

Thursday 21 August 2014 4:53:52 pm

Hello Tomasz,

Your question would prolly get better responses if asked in the proper forum, RE: http://share.ez.no/forums/ez-publish-5-platform

Sorry I don't have an answer. Best of luck.

I hope this helps...

Cheers,
Heath

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from