-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented logic for liip-theme bundle #1
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
preset: symfony | ||
|
||
enabled: | ||
- concat_with_spaces | ||
- ordered_use | ||
- short_array_syntax | ||
|
||
disabled: | ||
- concat_without_spaces | ||
- phpdoc_align | ||
- phpdoc_indent | ||
- phpdoc_to_comment | ||
- blankline_after_open_tag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
sudo: false | ||
|
||
language: php | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
- downloads | ||
|
||
matrix: | ||
include: | ||
- php: 5.5 | ||
- php: 7.0 | ||
|
||
before_script: | ||
- phpenv config-rm xdebug.ini | ||
- composer self-update | ||
- composer install --prefer-dist --no-interaction | ||
|
||
script: | ||
- vendor/bin/phpunit | ||
|
||
notifications: | ||
slack: | ||
secure: "Gd3/1e0pBKvJv1UhWpBkWijJpmSWlarg6uPBJO0h4z1IpkZjd++jOjhmOQ7n+yMfuapQuJTcVOK0yIWu7orJoGAKFkBlMEIrLk1xMAG9phjjMLUO0FWgcQ3eVW5mTyfMBtClz4OL5wXckw17ohtXHDK8qnI0Hz9Qj8Rqgf2OZhM=" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CHANGELOG for Sulu | ||
================== | ||
|
||
* dev-develop | ||
* FEATURE #1 Introduced liip/theme-bundle to enable theming |
104 changes: 104 additions & 0 deletions
104
DependencyInjection/CompilerPass/ImageFormatCompilerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ThemeBundle\DependencyInjection\CompilerPass; | ||
|
||
use Sulu\Bundle\MediaBundle\Media\FormatLoader\XmlFormatLoader; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* Class ImageFormatCompilerPass. | ||
*/ | ||
class ImageFormatCompilerPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* @var ContainerBuilder | ||
*/ | ||
protected $container; | ||
|
||
/** | ||
* You can modify the container here before it is dumped to PHP code. | ||
* | ||
* @param ContainerBuilder $container | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$this->container = $container; | ||
|
||
$formats = $this->loadThemeFormats( | ||
$container->getParameter('sulu_media.format_manager.default_imagine_options') | ||
); | ||
if ($container->hasParameter('sulu_media.image.formats')) { | ||
$formats = array_merge($container->getParameter('sulu_media.image.formats'), $formats); | ||
} | ||
|
||
$container->setParameter('sulu_media.image.formats', $formats); | ||
} | ||
|
||
/** | ||
* @param array $defaultOptions | ||
* | ||
* @return array | ||
*/ | ||
protected function loadThemeFormats($defaultOptions) | ||
{ | ||
$activeFormats = []; | ||
$activeTheme = $this->container->get('liip_theme.active_theme'); | ||
$bundles = $this->container->getParameter('kernel.bundles'); | ||
$configPaths = $this->container->getParameter('sulu_media.format_manager.config_paths'); | ||
$defaultConfigPath = 'config/image-formats.xml'; | ||
|
||
foreach ($activeTheme->getThemes() as $theme) { | ||
foreach ($bundles as $bundleName => $bundle) { | ||
$reflector = new \ReflectionClass($bundle); | ||
$configPath = $defaultConfigPath; | ||
if (isset($configPaths[$theme])) { | ||
$configPath = $configPaths[$theme]; | ||
} | ||
$fullPath = sprintf( | ||
'%s/Resources/themes/%s/%s', | ||
dirname($reflector->getFileName()), | ||
$theme, | ||
$configPath | ||
); | ||
|
||
if (file_exists($fullPath)) { | ||
$this->setFormatsFromFile($fullPath, $activeFormats, $defaultOptions); | ||
} | ||
} | ||
} | ||
|
||
return $activeFormats; | ||
} | ||
|
||
/** | ||
* @param $fullPath | ||
* @param $activeFormats | ||
* @param $defaultOptions | ||
*/ | ||
protected function setFormatsFromFile($fullPath, &$activeFormats, $defaultOptions) | ||
{ | ||
$folder = dirname($fullPath); | ||
$fileName = basename($fullPath); | ||
|
||
$locator = new FileLocator($folder); | ||
$loader = new XmlFormatLoader($locator); | ||
$loader->setDefaultOptions($defaultOptions); | ||
$themeFormats = $loader->load($fileName); | ||
foreach ($themeFormats as $format) { | ||
if (isset($format['name']) && !array_key_exists($format['name'], $activeFormats)) { | ||
$activeFormats[$format['name']] = $format; | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ThemeBundle\DependencyInjection\CompilerPass; | ||
|
||
use Sulu\Bundle\ThemeBundle\StructureProvider\WebspaceStructureProvider; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class WebspaceStructureProviderCompilerPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition('sulu.content.webspace_structure_provider')) { | ||
return; | ||
} | ||
|
||
$definition = $container->getDefinition('sulu.content.webspace_structure_provider'); | ||
$definition->setClass(WebspaceStructureProvider::class); | ||
$definition->addArgument(new Reference('sulu_core.webspace.webspace_manager')); | ||
$definition->addArgument(new Reference('liip_theme.active_theme')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ThemeBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
||
/** | ||
* This is the class that loads and manages your bundle configuration. | ||
* | ||
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} | ||
*/ | ||
class SuluThemeExtension extends Extension | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); | ||
$loader->load(sprintf('%s.xml', $container->getParameter('sulu.context'))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\ThemeBundle\EventListener; | ||
|
||
use Liip\ThemeBundle\ActiveTheme; | ||
use Sulu\Bundle\PreviewBundle\Preview\Events\PreRenderEvent; | ||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
|
||
/** | ||
* Listener which applies the configured theme. | ||
*/ | ||
class SetThemeEventListener | ||
{ | ||
/** | ||
* @var ActiveTheme | ||
*/ | ||
private $activeTheme; | ||
|
||
/** | ||
* @param ActiveTheme $activeTheme | ||
*/ | ||
public function __construct(ActiveTheme $activeTheme) | ||
{ | ||
$this->activeTheme = $activeTheme; | ||
} | ||
|
||
/** | ||
* Set the active theme if there is a portal. | ||
* | ||
* @param GetResponseEvent $event | ||
*/ | ||
public function setActiveThemeOnRequest(GetResponseEvent $event) | ||
{ | ||
if (!$event->isMasterRequest() | ||
|| null === ($attributes = $event->getRequest()->get('_sulu')) | ||
|| null === ($webspace = $attributes->getAttribute('webspace')) | ||
|| null === ($theme = $webspace->getTheme()) | ||
) { | ||
return; | ||
} | ||
|
||
$this->activeTheme->setName($theme); | ||
} | ||
|
||
/** | ||
* Set the active theme for a preview rendering. | ||
* | ||
* @param PreRenderEvent $event | ||
*/ | ||
public function setActiveThemeOnPreviewPreRender(PreRenderEvent $event) | ||
{ | ||
$this->activeTheme->setName($event->getAttribute('webspace')->getTheme()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# SuluThemeBundle | ||
|
||
[![Build Status](https://travis-ci.org/sulu/SuluThemeBundle.svg?branch=develop)](https://travis-ci.org/sulu/SuluThemeBundle) | ||
|
||
This package enables a basic theming for sulu. It uses liip/theme-bundle to extend the discovery feature of twig. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service id="sulu_website.event_listener.set_theme" | ||
class="Sulu\Bundle\ThemeBundle\EventListener\SetThemeEventListener"> | ||
<argument type="service" id="liip_theme.active_theme"/> | ||
|
||
<tag name="kernel.event_listener" event="%sulu_preview.events.pre-render%" | ||
method="setActiveThemeOnPreviewPreRender"/> | ||
</service> | ||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<service id="sulu_theme.event_listener.set_theme" | ||
class="Sulu\Bundle\ThemeBundle\EventListener\SetThemeEventListener"> | ||
<argument type="service" id="liip_theme.active_theme"/> | ||
|
||
<tag name="kernel.event_listener" event="kernel.request" method="setActiveThemeOnRequest"/> | ||
</service> | ||
</services> | ||
</container> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use kernel event listener (request analyzer isn't lazy any more)