diff --git a/bundle/DependencyInjection/Configuration.php b/bundle/DependencyInjection/Configuration.php index c16b019..ed73989 100644 --- a/bundle/DependencyInjection/Configuration.php +++ b/bundle/DependencyInjection/Configuration.php @@ -21,27 +21,22 @@ public function getConfigTreeBuilder() $rootNode ->children() - ->arrayNode('design') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('list') - ->useAttributeAsKey('design_name') - ->example(['my_design' => ['theme1', 'theme2']]) - ->prototype('array') - ->info('A design is a labeled collection of themes. Theme order defines the fallback order.') - ->prototype('scalar')->end() - ->end() - ->end() - ->arrayNode('override_paths') - ->info('Directories to add to the override list for templates. Those directories will be checked before theme directories.') - ->prototype('scalar')->end() - ->end() - ->booleanNode('disable_assets_pre_resolution') - ->info('If set to true, assets path won\'t be pre-resolved at compile time.') - ->defaultValue('%kernel.debug%') - ->end() + ->arrayNode('design_list') + ->useAttributeAsKey('design_name') + ->example(['my_design' => ['theme1', 'theme2']]) + ->prototype('array') + ->info('A design is a labeled collection of themes. Theme order defines the fallback order.') + ->prototype('scalar')->end() ->end() ->end() + ->arrayNode('template_override_paths') + ->info('Directories to add to the override list for templates. Those directories will be checked before theme directories.') + ->prototype('scalar')->end() + ->end() + ->booleanNode('disable_assets_pre_resolution') + ->info('If set to true, assets path won\'t be pre-resolved at compile time.') + ->defaultValue('%kernel.debug%') + ->end() ->arrayNode('phpstorm') ->addDefaultsIfNotSet() ->children() @@ -54,20 +49,6 @@ public function getConfigTreeBuilder() ->end() ->end(); - $systemNode = $this->generateScopeBaseNode($rootNode); - $systemNode - ->scalarNode('design') - ->cannotBeEmpty() - ->info('Name of the design to use. Must be one of the declared ones in the "design" key.') - ->end() - ->arrayNode('twig_globals') - ->info('Variables available in all Twig templates for current SiteAccess.') - ->normalizeKeys(false) - ->useAttributeAsKey('variable_name') - ->example(array('foo' => '"bar"', 'pi' => 3.14)) - ->prototype('variable')->end() - ->end(); - return $treeBuilder; } } diff --git a/bundle/DependencyInjection/DesignConfigParser.php b/bundle/DependencyInjection/DesignConfigParser.php new file mode 100644 index 0000000..2a1b83e --- /dev/null +++ b/bundle/DependencyInjection/DesignConfigParser.php @@ -0,0 +1,41 @@ +setContextualParameter('design', $currentScope, $scopeSettings['design']); + } + } + + public function preMap(array $config, ContextualizerInterface $contextualizer) + { + } + + public function postMap(array $config, ContextualizerInterface $contextualizer) + { + } + + public function addSemanticConfig(NodeBuilder $nodeBuilder) + { + $nodeBuilder + ->scalarNode('design') + ->cannotBeEmpty() + ->info('Name of the design to use. Must be declared in ezdesign.design_list') + ->end(); + } +} diff --git a/bundle/DependencyInjection/EzPlatformDesignEngineExtension.php b/bundle/DependencyInjection/EzPlatformDesignEngineExtension.php index c4e07a1..528669a 100644 --- a/bundle/DependencyInjection/EzPlatformDesignEngineExtension.php +++ b/bundle/DependencyInjection/EzPlatformDesignEngineExtension.php @@ -44,32 +44,14 @@ public function load(array $configs, ContainerBuilder $container) private function configureDesigns(array $config, ConfigurationProcessor $processor, ContainerBuilder $container) { - // Always add _base theme to the list. - foreach ($config['design']['list'] as $design => &$themes) { - $themes[] = '_base'; - } - $container->setParameter('ezdesign.design_list', $config['design']['list']); - $container->setParameter('ezdesign.templates_override_paths', $config['design']['override_paths']); - $container->setParameter('ezdesign.asset_resolution.disabled', $config['design']['disable_assets_pre_resolution']); + // Always add "standard" design to the list (defaults to application level & override paths only) + $config['design_list'] += ['standard' => []]; + $container->setParameter('ezdesign.design_list', $config['design_list']); + $container->setParameter('ezdesign.templates_override_paths', $config['template_override_paths']); + $container->setParameter('ezdesign.asset_resolution.disabled', $config['disable_assets_pre_resolution']); // PHPStorm settings $container->setParameter('ezdesign.phpstorm.enabled', $config['phpstorm']['enabled']); $container->setParameter('ezdesign.phpstorm.twig_config_path', $config['phpstorm']['twig_config_path']); - - // SiteAccess aware settings - $processor->mapConfig( - $config, - function ($scopeSettings, $currentScope, ContextualizerInterface $contextualizer) use ($config) { - if (isset($scopeSettings['design'])) { - if (!isset($config['design']['list'][$scopeSettings['design']])) { - throw new InvalidArgumentException( - "Selected design for $currentScope '{$scopeSettings['design']}' is invalid. Did you forget to define it?" - ); - } - - $contextualizer->setContextualParameter('design', $currentScope, $scopeSettings['design']); - } - } - ); } } diff --git a/bundle/EzPlatformDesignEngineBundle.php b/bundle/EzPlatformDesignEngineBundle.php index 83ca60f..d9526b8 100644 --- a/bundle/EzPlatformDesignEngineBundle.php +++ b/bundle/EzPlatformDesignEngineBundle.php @@ -13,6 +13,7 @@ use EzSystems\EzPlatformDesignEngineBundle\DependencyInjection\Compiler\AssetThemePass; use EzSystems\EzPlatformDesignEngineBundle\DependencyInjection\Compiler\PHPStormPass; use EzSystems\EzPlatformDesignEngineBundle\DependencyInjection\Compiler\TwigThemePass; +use EzSystems\EzPlatformDesignEngineBundle\DependencyInjection\DesignConfigParser; use EzSystems\EzPlatformDesignEngineBundle\DependencyInjection\EzPlatformDesignEngineExtension; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -23,6 +24,12 @@ class EzPlatformDesignEngineBundle extends Bundle public function build(ContainerBuilder $container) { parent::build($container); + + /** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension $eZExtension */ + $eZExtension = $container->getExtension('ezpublish'); + $eZExtension->addConfigParser(new DesignConfigParser()); + $eZExtension->addDefaultSettings(__DIR__ . '/Resources/config', ['default_settings.yml']); + $container->addCompilerPass(new TwigThemePass()); $container->addCompilerPass(new AssetThemePass(), PassConfig::TYPE_OPTIMIZE); $container->addCompilerPass(new AssetPathResolutionPass(), PassConfig::TYPE_OPTIMIZE); diff --git a/bundle/Resources/config/default_settings.yml b/bundle/Resources/config/default_settings.yml index 1de505d..ac1f879 100644 --- a/bundle/Resources/config/default_settings.yml +++ b/bundle/Resources/config/default_settings.yml @@ -1,3 +1,2 @@ parameters: - ezdesign.default.design: ~ - ezdesign.default.twig_globals: {} + ezsettings.default.design: standard diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index a054f62..8cb11b3 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -12,8 +12,7 @@ parameters: services: ezdesign.template_name_resolver: class: EzSystems\EzPlatformDesignEngine\Templating\ThemeTemplateNameResolver - arguments: ["$design;ezdesign$"] - lazy: true + arguments: ["$design$"] ezdesign.template_path_registry: class: EzSystems\EzPlatformDesignEngine\Templating\TemplatePathRegistry @@ -54,4 +53,4 @@ services: - "@ezdesign.asset_path_resolver" - "@assets._default_package" calls: - - [setCurrentDesign, ["$design;ezdesign"]] + - [setCurrentDesign, ["$design$"]] diff --git a/doc/assets.md b/doc/assets.md index 83faedd..57b4498 100644 --- a/doc/assets.md +++ b/doc/assets.md @@ -48,9 +48,8 @@ This behavior can however be controlled by `disable_assets_pre_resolution` setti ```yaml # ezplatform_prod.yml -ezpublish: - design: - # Force runtime resolution - # Default value is '%kernel.debug%' - disable_assets_pre_resolution: true +ezdesign: + # Force runtime resolution + # Default value is '%kernel.debug%' + disable_assets_pre_resolution: true ``` \ No newline at end of file diff --git a/doc/index.md b/doc/index.md index 8e77d9f..74899a5 100644 --- a/doc/index.md +++ b/doc/index.md @@ -25,19 +25,44 @@ To define and use a design, you need to: Here is a simple example: ```yaml +# ezplatform.yml +ezdesign: + # You declare every available designs under "design_list". + design_list: + # my_design will be composed of "theme1" and "theme2" + # "theme1" will be the first tried. If the template cannot be found in "theme1", "theme2" will be tried out. + my_design: [theme1, theme2] + ezpublish: - design: - # You declare every available designs under "list". - list: - # my_design will be composed of "theme1" and "theme2" - # "theme1" will be the first tried. If the template cannot be found in "theme1", "theme2" will be tried out. - my_design: [theme1, theme2] + # ... system: my_siteaccess: # my_siteaccess will use "my_design" design: my_design ``` +> **Note**: Default design for a SiteAccess is `standard` which contains no themes. +> If one is using `@ezdesign` Twig namespace and/or `ezdesign` asset package, the system will always fallback to +> application level and override directories for templates/assets lookup. + ## Usage * [Usage with templates](templates.md) * [Usage with assets](assets.md) + +## Referencing current design +It is possible to reference current design in order to inject it into a service. +To do so, one just need to reference `$design$` dynamic setting: + +```yaml +services: + my_service: + class: Foo\Bar + arguments: ["$design$"] +``` + +It is also possible to use the `ConfigResolver` service (`ezpublish.config.resolver`): + +```php +// In a controller +$currentDesign = $this->getConfigResolver->getParameter('design'); +``` diff --git a/doc/templates.md b/doc/templates.md index 5a7aa4b..1f0aa22 100644 --- a/doc/templates.md +++ b/doc/templates.md @@ -45,11 +45,10 @@ Default fallback order is the following: It is possible to add addition global override directories, similar to `app/Resources/views/`. ```yaml -ezpublish: - design: - template_override_paths: - - "%kernel.root_dir%/another_override_directory" - - "/some/other/directory" +ezdesign: + template_override_paths: + - "%kernel.root_dir%/another_override_directory" + - "/some/other/directory" ``` > `app/Resources/views/` will **always** be the top level override directory. @@ -68,13 +67,12 @@ if your PHPStorm project root doesn't match your Symfony project root. Default config: ```yaml -ezpublish: - design: - phpstorm: - - # Activates PHPStorm support - enabled: '%kernel.debug%' - - # Path where to store PHPStorm configuration file for additional Twig namespaces (ide-twig.json). - twig_config_path: '%kernel.root_dir%/..' +ezdesign: + phpstorm: + + # Activates PHPStorm support + enabled: '%kernel.debug%' + + # Path where to store PHPStorm configuration file for additional Twig namespaces (ide-twig.json). + twig_config_path: '%kernel.root_dir%/..' ```