From 43b56e950ce13cf7f3820dbad5bf5a5727497ab0 Mon Sep 17 00:00:00 2001 From: Mario Fehr Date: Fri, 21 Aug 2020 18:58:01 +0200 Subject: [PATCH 01/15] Update composer.json --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 0e9e37e..dfa5973 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,9 @@ "php": "^7.2", "liip/theme-bundle": "^1.5", "sulu/sulu": "^2.0", - "symfony/config": "^4.3", - "symfony/dependency-injection": "^4.3", - "symfony/http-kernel": "^4.3" + "symfony/config": "^5.1", + "symfony/dependency-injection": "^5.1", + "symfony/http-kernel": "^5.1" }, "require-dev": { "jackalope/jackalope-doctrine-dbal": "^1.3", @@ -29,7 +29,7 @@ "phpstan/phpstan-doctrine": "^0.12", "phpstan/phpstan-phpunit": "^0.12", "phpstan/phpstan-symfony": "^0.12", - "symfony/dotenv": "^4.3", + "symfony/dotenv": "^5.1", "thecodingmachine/phpstan-strict-rules": "^0.12" }, "conflict": { From 253065d72ad673d3b3b5856671bbf6396c021803 Mon Sep 17 00:00:00 2001 From: Mario Fehr Date: Fri, 21 Aug 2020 19:06:53 +0200 Subject: [PATCH 02/15] Update composer.json --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index dfa5973..f414a4a 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,6 @@ ], "require": { "php": "^7.2", - "liip/theme-bundle": "^1.5", "sulu/sulu": "^2.0", "symfony/config": "^5.1", "symfony/dependency-injection": "^5.1", From 2ab31c4f4aac3f9c336eed202c43fce2926be25d Mon Sep 17 00:00:00 2001 From: Mario Fehr Date: Fri, 21 Aug 2020 20:14:40 +0200 Subject: [PATCH 03/15] switch from LiipThemeBundle to SyliusThemeBundle --- .../CompilerPass/ImageFormatCompilerPass.php | 9 +++--- .../WebspaceStructureProviderCompilerPass.php | 3 +- EventListener/SetThemeEventListener.php | 30 ++++++++++++------- Resources/config/admin.xml | 3 +- Resources/config/website.xml | 3 +- .../WebspaceStructureProvider.php | 28 ++++++++++------- composer.json | 3 +- 7 files changed, 50 insertions(+), 29 deletions(-) diff --git a/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php b/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php index 67cbeca..5d3c419 100644 --- a/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php +++ b/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php @@ -13,6 +13,7 @@ use Liip\ThemeBundle\ActiveTheme; use Sulu\Bundle\MediaBundle\DependencyInjection\AbstractImageFormatCompilerPass; +use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; /** @@ -27,12 +28,12 @@ protected function getFiles(ContainerBuilder $container) { $files = []; - /** @var ActiveTheme $activeTheme */ - $activeTheme = $container->get('liip_theme.active_theme'); + /** @var ThemeRepositoryInterface $activeTheme */ + $activeTheme = $container->get('sylius.repository.theme'); $bundles = $container->getParameter('kernel.bundles'); $configPath = 'config/image-formats.xml'; - foreach ($activeTheme->getThemes() as $theme) { + foreach ($activeTheme->findAll() as $theme) { foreach ($bundles as $bundleName => $bundle) { $bundleReflection = new \ReflectionClass($bundle); $fileName = $bundleReflection->getFileName(); @@ -44,7 +45,7 @@ protected function getFiles(ContainerBuilder $container) $path = sprintf( '%s/Resources/themes/%s/%s', dirname($fileName), - $theme, + $theme->getName(), $configPath ); diff --git a/DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php b/DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php index 55eac93..be26ea8 100644 --- a/DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php +++ b/DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php @@ -30,6 +30,7 @@ public function process(ContainerBuilder $container): void $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')); + $definition->addArgument(new Reference('sylius.repository.theme')); + $definition->addArgument(new Reference('sylius.theme.context.settable')); } } diff --git a/EventListener/SetThemeEventListener.php b/EventListener/SetThemeEventListener.php index 5bb8ab6..d3af00a 100644 --- a/EventListener/SetThemeEventListener.php +++ b/EventListener/SetThemeEventListener.php @@ -11,29 +11,32 @@ namespace Sulu\Bundle\ThemeBundle\EventListener; -use Liip\ThemeBundle\ActiveTheme; use Sulu\Bundle\PreviewBundle\Preview\Events\PreRenderEvent; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Sylius\Bundle\ThemeBundle\Context\SettableThemeContext; +use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * Listener which applies the configured theme. */ class SetThemeEventListener { - /** - * @var ActiveTheme - */ - private $activeTheme; + /** @var ThemeRepositoryInterface */ + private $themeRepository; - public function __construct(ActiveTheme $activeTheme) + /** @var SettableThemeContext */ + private $themeContext; + + public function __construct(ThemeRepositoryInterface $themeRepository, SettableThemeContext $themeContext) { - $this->activeTheme = $activeTheme; + $this->themeRepository = $themeRepository; + $this->themeContext = $themeContext; } /** * Set the active theme if there is a portal. */ - public function setActiveThemeOnRequest(GetResponseEvent $event): void + public function setActiveThemeOnRequest(RequestEvent $event): void { if (null === ($attributes = $event->getRequest()->get('_sulu')) || null === ($webspace = $attributes->getAttribute('webspace')) @@ -42,7 +45,9 @@ public function setActiveThemeOnRequest(GetResponseEvent $event): void return; } - $this->activeTheme->setName($theme); + $this->themeContext->setTheme( + $this->themeRepository->findOneByName($theme) + ); } /** @@ -50,6 +55,9 @@ public function setActiveThemeOnRequest(GetResponseEvent $event): void */ public function setActiveThemeOnPreviewPreRender(PreRenderEvent $event): void { - $this->activeTheme->setName($event->getAttribute('webspace')->getTheme()); + + $this->themeContext->setTheme( + $this->themeRepository->findOneByName($event->getAttribute('webspace')->getTheme()) + ); } } diff --git a/Resources/config/admin.xml b/Resources/config/admin.xml index 07e7fef..ed3827a 100644 --- a/Resources/config/admin.xml +++ b/Resources/config/admin.xml @@ -5,7 +5,8 @@ - + + diff --git a/Resources/config/website.xml b/Resources/config/website.xml index 8b59130..c67f151 100644 --- a/Resources/config/website.xml +++ b/Resources/config/website.xml @@ -6,7 +6,8 @@ - + + diff --git a/StructureProvider/WebspaceStructureProvider.php b/StructureProvider/WebspaceStructureProvider.php index bc7b686..b992aca 100644 --- a/StructureProvider/WebspaceStructureProvider.php +++ b/StructureProvider/WebspaceStructureProvider.php @@ -12,12 +12,13 @@ namespace Sulu\Bundle\ThemeBundle\StructureProvider; use Doctrine\Common\Cache\Cache; -use Liip\ThemeBundle\ActiveTheme; use Sulu\Component\Content\Compat\Structure\PageBridge; use Sulu\Component\Content\Compat\StructureInterface; use Sulu\Component\Content\Compat\StructureManagerInterface; use Sulu\Component\Webspace\Manager\WebspaceManagerInterface; use Sulu\Component\Webspace\StructureProvider\WebspaceStructureProvider as BaseWebspaceStructureProvider; +use Sylius\Bundle\ThemeBundle\Context\SettableThemeContext; +use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface; /** * Provide templates which are implemented in a single webspace. @@ -29,22 +30,25 @@ class WebspaceStructureProvider extends BaseWebspaceStructureProvider */ protected $webspaceManager; - /** - * @var ActiveTheme - */ - protected $activeTheme; + /** @var ThemeRepositoryInterface */ + private $themeRepository; + + /** @var SettableThemeContext */ + private $themeContext; public function __construct( \Twig_Environment $twig, StructureManagerInterface $structureManager, Cache $cache, WebspaceManagerInterface $webspaceManager, - ActiveTheme $activeTheme + ThemeRepositoryInterface $themeRepository, + SettableThemeContext $themeContext ) { parent::__construct($twig, $structureManager, $cache); $this->webspaceManager = $webspaceManager; - $this->activeTheme = $activeTheme; + $this->themeRepository = $themeRepository; + $this->themeContext = $themeContext; } /** @@ -54,7 +58,7 @@ public function __construct( */ protected function loadStructures($webspaceKey): array { - $before = $this->activeTheme->getName(); + $before = $this->themeContext->getTheme()->getName(); $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey); if (!$webspace) { @@ -62,7 +66,9 @@ protected function loadStructures($webspaceKey): array } if (null !== $webspace->getTheme()) { - $this->activeTheme->setName($webspace->getTheme()); + $this->themeContext->setTheme( + $this->themeRepository->findOneByName($webspace->getTheme()) + ); } $structures = []; @@ -75,7 +81,9 @@ protected function loadStructures($webspaceKey): array $structures[] = $page; } } - $this->activeTheme->setName($before); + $this->themeContext->setTheme( + $this->themeRepository->findOneByName($before) + ); $this->cache->save($webspaceKey, $keys); return $structures; diff --git a/composer.json b/composer.json index f414a4a..02383c1 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "sulu/sulu": "^2.0", "symfony/config": "^5.1", "symfony/dependency-injection": "^5.1", - "symfony/http-kernel": "^5.1" + "symfony/http-kernel": "^5.1", + "sylius/theme-bundle": "^2.0" }, "require-dev": { "jackalope/jackalope-doctrine-dbal": "^1.3", From b6af8ae2861408b5d3a1950ab6755f76010631eb Mon Sep 17 00:00:00 2001 From: Mario Fehr Date: Fri, 21 Aug 2020 23:19:11 +0200 Subject: [PATCH 04/15] Try to fix tests. --- EventListener/SetThemeEventListener.php | 8 ++- Tests/Application/Kernel.php | 4 +- Tests/Application/config/sylius_theme.yaml | 3 ++ .../SetThemeEventListenerTest.php | 53 +++++++++++++------ composer.json | 3 +- 5 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 Tests/Application/config/sylius_theme.yaml diff --git a/EventListener/SetThemeEventListener.php b/EventListener/SetThemeEventListener.php index d3af00a..02aa36e 100644 --- a/EventListener/SetThemeEventListener.php +++ b/EventListener/SetThemeEventListener.php @@ -21,10 +21,14 @@ */ class SetThemeEventListener { - /** @var ThemeRepositoryInterface */ + /** + * @var ThemeRepositoryInterface + */ private $themeRepository; - /** @var SettableThemeContext */ + /** + * @var SettableThemeContext + */ private $themeContext; public function __construct(ThemeRepositoryInterface $themeRepository, SettableThemeContext $themeContext) diff --git a/Tests/Application/Kernel.php b/Tests/Application/Kernel.php index 2e02eba..c1c0db2 100644 --- a/Tests/Application/Kernel.php +++ b/Tests/Application/Kernel.php @@ -11,9 +11,9 @@ namespace Sulu\Bundle\ThemeBundle\Tests\Application; -use Liip\ThemeBundle\LiipThemeBundle; use Sulu\Bundle\TestBundle\Kernel\SuluTestKernel; use Sulu\Bundle\ThemeBundle\SuluThemeBundle; +use Sylius\Bundle\ThemeBundle\SyliusThemeBundle; use Symfony\Component\Config\Loader\LoaderInterface; class Kernel extends SuluTestKernel @@ -34,7 +34,7 @@ public function registerBundles() return array_merge( parent::registerBundles(), [ - new LiipThemeBundle(), + new SyliusThemeBundle(), new SuluThemeBundle(), ] ); diff --git a/Tests/Application/config/sylius_theme.yaml b/Tests/Application/config/sylius_theme.yaml new file mode 100644 index 0000000..4d34199 --- /dev/null +++ b/Tests/Application/config/sylius_theme.yaml @@ -0,0 +1,3 @@ +sylius_theme: + sources: + test: ~ diff --git a/Tests/Unit/EventListener/SetThemeEventListenerTest.php b/Tests/Unit/EventListener/SetThemeEventListenerTest.php index c1d38f6..c4e2e8b 100644 --- a/Tests/Unit/EventListener/SetThemeEventListenerTest.php +++ b/Tests/Unit/EventListener/SetThemeEventListenerTest.php @@ -11,27 +11,35 @@ namespace Sulu\Bundle\ThemeBundle\Tests\Unit\EventListener; -use Liip\ThemeBundle\ActiveTheme; +use DG\BypassFinals; use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\PreviewBundle\Preview\Events\PreRenderEvent; use Sulu\Bundle\ThemeBundle\EventListener\SetThemeEventListener; use Sulu\Component\Webspace\Analyzer\Attributes\RequestAttributes; use Sulu\Component\Webspace\Webspace; +use Sylius\Bundle\ThemeBundle\Configuration\Test\TestThemeConfigurationManagerInterface; +use Sylius\Bundle\ThemeBundle\Context\SettableThemeContext; +use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; class SetThemeEventListenerTest extends TestCase { /** - * @var ObjectProphecy|ActiveTheme + * @var ObjectProphecy|ThemeRepositoryInterface */ - private $activeTheme; + private $themeRepository; + + /** + * @var ObjectProphecy|SettableThemeContext + */ + private $themeContext; /** * @var string */ - private $theme = 'test'; + private $theme = 'theme/name'; /** * @var ObjectProphecy|Webspace @@ -45,11 +53,14 @@ class SetThemeEventListenerTest extends TestCase public function setUp(): void { - $this->activeTheme = $this->prophesize(ActiveTheme::class); + BypassFinals::enable(); + + $this->themeRepository = $this->prophesize(ThemeRepositoryInterface::class); + $this->themeContext = $this->prophesize(SettableThemeContext::class); $this->webspace = $this->prophesize(Webspace::class); $this->webspace->getTheme()->willReturn($this->theme); - $this->listener = new SetThemeEventListener($this->activeTheme->reveal()); + $this->listener = new SetThemeEventListener($this->themeRepository->reveal(), $this->themeContext->reveal()); } public function testEventListener(): void @@ -59,11 +70,13 @@ public function testEventListener(): void $attributes->getAttribute('webspace')->willReturn($this->webspace->reveal()); $request->get('_sulu')->willReturn($attributes->reveal()); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request->reveal()); $event->isMasterRequest()->willReturn(true); - $this->activeTheme->setName($this->theme)->shouldBeCalled(); + $this->themeContext->setTheme( + $this->themeRepository->findOneByName($this->theme) + )->shouldBeCalled(); $this->listener->setActiveThemeOnRequest($event->reveal()); } @@ -75,11 +88,13 @@ public function testEventListenerNotMaster(): void $attributes->getAttribute('webspace')->willReturn($this->webspace->reveal()); $request->get('_sulu')->willReturn($attributes->reveal()); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request->reveal()); $event->isMasterRequest()->willReturn(false); - $this->activeTheme->setName($this->theme)->shouldBeCalled(); + $this->themeContext->setTheme( + $this->themeRepository->findOneByName($this->theme) + )->shouldBeCalled(); $this->listener->setActiveThemeOnRequest($event->reveal()); } @@ -91,11 +106,13 @@ public function testEventListenerNoWebspace(): void $attributes->getAttribute('webspace')->willReturn(null); $request->get('_sulu')->willReturn($attributes->reveal()); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request->reveal()); $event->isMasterRequest()->willReturn(true); - $this->activeTheme->setName($this->theme)->shouldNotBeCalled(); + $this->themeContext->setTheme( + $this->themeRepository->findOneByName($this->theme) + )->shouldNotBeCalled(); $this->listener->setActiveThemeOnRequest($event->reveal()); } @@ -105,11 +122,13 @@ public function testEventListenerNoAttributes(): void $request = $this->prophesize(Request::class); $request->get('_sulu')->willReturn(null); - $event = $this->prophesize(GetResponseEvent::class); + $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request->reveal()); $event->isMasterRequest()->willReturn(true); - $this->activeTheme->setName($this->theme)->shouldNotBeCalled(); + $this->themeContext->setTheme( + $this->themeRepository->findOneByName($this->theme) + )->shouldNotBeCalled(); $this->listener->setActiveThemeOnRequest($event->reveal()); } @@ -119,7 +138,9 @@ public function testEventListenerOnPreview(): void $attributes = $this->prophesize(RequestAttributes::class); $attributes->getAttribute('webspace', null)->willReturn($this->webspace->reveal()); - $this->activeTheme->setName($this->theme)->shouldBeCalled(); + $this->themeContext->setTheme( + $this->themeRepository->findOneByName($this->theme) + )->shouldBeCalled(); $this->listener->setActiveThemeOnPreviewPreRender( new PreRenderEvent($attributes->reveal()) diff --git a/composer.json b/composer.json index 02383c1..7d2c7d3 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "phpstan/phpstan-phpunit": "^0.12", "phpstan/phpstan-symfony": "^0.12", "symfony/dotenv": "^5.1", - "thecodingmachine/phpstan-strict-rules": "^0.12" + "thecodingmachine/phpstan-strict-rules": "^0.12", + "dg/bypass-finals": "^1.2" }, "conflict": { "liip/theme-bundle": "1.6.0" From bdd85b8a5e4b260d5b3f995e2185bc25f3226742 Mon Sep 17 00:00:00 2001 From: Mario Fehr Date: Wed, 26 Aug 2020 07:28:01 +0200 Subject: [PATCH 05/15] remove final bypass. --- Tests/Unit/EventListener/SetThemeEventListenerTest.php | 2 -- composer.json | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Tests/Unit/EventListener/SetThemeEventListenerTest.php b/Tests/Unit/EventListener/SetThemeEventListenerTest.php index c4e2e8b..b5c61eb 100644 --- a/Tests/Unit/EventListener/SetThemeEventListenerTest.php +++ b/Tests/Unit/EventListener/SetThemeEventListenerTest.php @@ -53,8 +53,6 @@ class SetThemeEventListenerTest extends TestCase public function setUp(): void { - BypassFinals::enable(); - $this->themeRepository = $this->prophesize(ThemeRepositoryInterface::class); $this->themeContext = $this->prophesize(SettableThemeContext::class); $this->webspace = $this->prophesize(Webspace::class); diff --git a/composer.json b/composer.json index 7d2c7d3..02383c1 100644 --- a/composer.json +++ b/composer.json @@ -30,8 +30,7 @@ "phpstan/phpstan-phpunit": "^0.12", "phpstan/phpstan-symfony": "^0.12", "symfony/dotenv": "^5.1", - "thecodingmachine/phpstan-strict-rules": "^0.12", - "dg/bypass-finals": "^1.2" + "thecodingmachine/phpstan-strict-rules": "^0.12" }, "conflict": { "liip/theme-bundle": "1.6.0" From 187ccf8b6942bfc0c8be238f8d637e491ebb701d Mon Sep 17 00:00:00 2001 From: Mario Fehr Date: Wed, 26 Aug 2020 07:54:15 +0200 Subject: [PATCH 06/15] fix pipline --- EventListener/SetThemeEventListener.php | 1 - Tests/Unit/EventListener/SetThemeEventListenerTest.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/EventListener/SetThemeEventListener.php b/EventListener/SetThemeEventListener.php index 02aa36e..45aa105 100644 --- a/EventListener/SetThemeEventListener.php +++ b/EventListener/SetThemeEventListener.php @@ -59,7 +59,6 @@ public function setActiveThemeOnRequest(RequestEvent $event): void */ public function setActiveThemeOnPreviewPreRender(PreRenderEvent $event): void { - $this->themeContext->setTheme( $this->themeRepository->findOneByName($event->getAttribute('webspace')->getTheme()) ); diff --git a/Tests/Unit/EventListener/SetThemeEventListenerTest.php b/Tests/Unit/EventListener/SetThemeEventListenerTest.php index b5c61eb..7b3fd59 100644 --- a/Tests/Unit/EventListener/SetThemeEventListenerTest.php +++ b/Tests/Unit/EventListener/SetThemeEventListenerTest.php @@ -11,14 +11,12 @@ namespace Sulu\Bundle\ThemeBundle\Tests\Unit\EventListener; -use DG\BypassFinals; use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; use Sulu\Bundle\PreviewBundle\Preview\Events\PreRenderEvent; use Sulu\Bundle\ThemeBundle\EventListener\SetThemeEventListener; use Sulu\Component\Webspace\Analyzer\Attributes\RequestAttributes; use Sulu\Component\Webspace\Webspace; -use Sylius\Bundle\ThemeBundle\Configuration\Test\TestThemeConfigurationManagerInterface; use Sylius\Bundle\ThemeBundle\Context\SettableThemeContext; use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface; use Symfony\Component\HttpFoundation\Request; From 4238a721083eb74959d3b94729944a3a04c771c1 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 11 Nov 2020 15:56:45 +0100 Subject: [PATCH 07/15] Cleanup and fix tests --- .gitignore | 2 + .travis.yml | 2 +- .../CompilerPass/ImageFormatCompilerPass.php | 10 +- .../WebspaceStructureProviderCompilerPass.php | 36 ----- EventListener/SetThemeEventListener.php | 14 +- Resources/config/website.xml | 1 - .../WebspaceStructureProvider.php | 91 ------------- SuluThemeBundle.php | 3 - .../SetThemeEventListenerTest.php | 58 ++++---- .../WebspaceStructureProviderTest.php | 124 ------------------ composer.json | 15 +-- 11 files changed, 55 insertions(+), 301 deletions(-) delete mode 100644 DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php delete mode 100644 StructureProvider/WebspaceStructureProvider.php delete mode 100644 Tests/Unit/StructureProvider/WebspaceStructureProviderTest.php diff --git a/.gitignore b/.gitignore index 095f17e..e8fe863 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ /Tests/Application/var/* /vendor/ +.env.local +.env.*.local /composer.phar /composer.lock .php_cs.cache diff --git a/.travis.yml b/.travis.yml index 6663f7c..074f299 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ cache: matrix: include: - - php: 7.2 + - php: 7.3 env: - COMPOSER_FLAGS="--prefer-lowest --prefer-stable --prefer-dist --no-interaction" - php: 7.4 diff --git a/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php b/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php index 5d3c419..63fa245 100644 --- a/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php +++ b/DependencyInjection/CompilerPass/ImageFormatCompilerPass.php @@ -11,7 +11,6 @@ namespace Sulu\Bundle\ThemeBundle\DependencyInjection\CompilerPass; -use Liip\ThemeBundle\ActiveTheme; use Sulu\Bundle\MediaBundle\DependencyInjection\AbstractImageFormatCompilerPass; use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -26,14 +25,13 @@ class ImageFormatCompilerPass extends AbstractImageFormatCompilerPass */ protected function getFiles(ContainerBuilder $container) { - $files = []; - - /** @var ThemeRepositoryInterface $activeTheme */ - $activeTheme = $container->get('sylius.repository.theme'); + /** @var ThemeRepositoryInterface $themeRepository */ + $themeRepository = $container->get('sylius.repository.theme'); $bundles = $container->getParameter('kernel.bundles'); $configPath = 'config/image-formats.xml'; - foreach ($activeTheme->findAll() as $theme) { + $files = []; + foreach ($themeRepository->findAll() as $theme) { foreach ($bundles as $bundleName => $bundle) { $bundleReflection = new \ReflectionClass($bundle); $fileName = $bundleReflection->getFileName(); diff --git a/DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php b/DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php deleted file mode 100644 index be26ea8..0000000 --- a/DependencyInjection/CompilerPass/WebspaceStructureProviderCompilerPass.php +++ /dev/null @@ -1,36 +0,0 @@ -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('sylius.repository.theme')); - $definition->addArgument(new Reference('sylius.theme.context.settable')); - } -} diff --git a/EventListener/SetThemeEventListener.php b/EventListener/SetThemeEventListener.php index 45aa105..ae06cad 100644 --- a/EventListener/SetThemeEventListener.php +++ b/EventListener/SetThemeEventListener.php @@ -49,9 +49,10 @@ public function setActiveThemeOnRequest(RequestEvent $event): void return; } - $this->themeContext->setTheme( - $this->themeRepository->findOneByName($theme) - ); + $theme = $this->themeRepository->findOneByName($theme); + if (null !== $theme) { + $this->themeContext->setTheme($theme); + } } /** @@ -59,8 +60,9 @@ public function setActiveThemeOnRequest(RequestEvent $event): void */ public function setActiveThemeOnPreviewPreRender(PreRenderEvent $event): void { - $this->themeContext->setTheme( - $this->themeRepository->findOneByName($event->getAttribute('webspace')->getTheme()) - ); + $theme = $this->themeRepository->findOneByName($event->getAttribute('webspace')->getTheme()); + if (null !== $theme) { + $this->themeContext->setTheme($theme); + } } } diff --git a/Resources/config/website.xml b/Resources/config/website.xml index c67f151..c5aab40 100644 --- a/Resources/config/website.xml +++ b/Resources/config/website.xml @@ -2,7 +2,6 @@ - diff --git a/StructureProvider/WebspaceStructureProvider.php b/StructureProvider/WebspaceStructureProvider.php deleted file mode 100644 index b992aca..0000000 --- a/StructureProvider/WebspaceStructureProvider.php +++ /dev/null @@ -1,91 +0,0 @@ -webspaceManager = $webspaceManager; - $this->themeRepository = $themeRepository; - $this->themeContext = $themeContext; - } - - /** - * {@inheritdoc} - * - * @return StructureInterface[] - */ - protected function loadStructures($webspaceKey): array - { - $before = $this->themeContext->getTheme()->getName(); - $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey); - - if (!$webspace) { - return []; - } - - if (null !== $webspace->getTheme()) { - $this->themeContext->setTheme( - $this->themeRepository->findOneByName($webspace->getTheme()) - ); - } - - $structures = []; - $keys = []; - /** @var PageBridge $page */ - foreach ($this->structureManager->getStructures() as $page) { - $template = sprintf('%s.html.twig', $page->getView()); - if ($this->templateExists($template)) { - $keys[] = $page->getKey(); - $structures[] = $page; - } - } - $this->themeContext->setTheme( - $this->themeRepository->findOneByName($before) - ); - $this->cache->save($webspaceKey, $keys); - - return $structures; - } -} diff --git a/SuluThemeBundle.php b/SuluThemeBundle.php index fa7d173..06a2727 100644 --- a/SuluThemeBundle.php +++ b/SuluThemeBundle.php @@ -12,7 +12,6 @@ namespace Sulu\Bundle\ThemeBundle; use Sulu\Bundle\ThemeBundle\DependencyInjection\CompilerPass\ImageFormatCompilerPass; -use Sulu\Bundle\ThemeBundle\DependencyInjection\CompilerPass\WebspaceStructureProviderCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -21,8 +20,6 @@ class SuluThemeBundle extends Bundle public function build(ContainerBuilder $container): void { parent::build($container); - - $container->addCompilerPass(new WebspaceStructureProviderCompilerPass()); $container->addCompilerPass(new ImageFormatCompilerPass()); } } diff --git a/Tests/Unit/EventListener/SetThemeEventListenerTest.php b/Tests/Unit/EventListener/SetThemeEventListenerTest.php index 7b3fd59..411a888 100644 --- a/Tests/Unit/EventListener/SetThemeEventListenerTest.php +++ b/Tests/Unit/EventListener/SetThemeEventListenerTest.php @@ -18,6 +18,7 @@ use Sulu\Component\Webspace\Analyzer\Attributes\RequestAttributes; use Sulu\Component\Webspace\Webspace; use Sylius\Bundle\ThemeBundle\Context\SettableThemeContext; +use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; @@ -25,24 +26,24 @@ class SetThemeEventListenerTest extends TestCase { /** - * @var ObjectProphecy|ThemeRepositoryInterface + * @var ThemeRepositoryInterface|ObjectProphecy */ private $themeRepository; /** - * @var ObjectProphecy|SettableThemeContext + * @var SettableThemeContext */ private $themeContext; /** - * @var string + * @var Webspace|ObjectProphecy */ - private $theme = 'theme/name'; + private $webspace; /** - * @var ObjectProphecy|Webspace + * @var ThemeInterface|ObjectProphecy */ - private $webspace; + private $theme; /** * @var SetThemeEventListener @@ -52,11 +53,12 @@ class SetThemeEventListenerTest extends TestCase public function setUp(): void { $this->themeRepository = $this->prophesize(ThemeRepositoryInterface::class); - $this->themeContext = $this->prophesize(SettableThemeContext::class); + $this->theme = $this->prophesize(ThemeInterface::class); + $this->themeContext = new SettableThemeContext(); $this->webspace = $this->prophesize(Webspace::class); - $this->webspace->getTheme()->willReturn($this->theme); + $this->webspace->getTheme()->willReturn('theme/name'); - $this->listener = new SetThemeEventListener($this->themeRepository->reveal(), $this->themeContext->reveal()); + $this->listener = new SetThemeEventListener($this->themeRepository->reveal(), $this->themeContext); } public function testEventListener(): void @@ -70,11 +72,13 @@ public function testEventListener(): void $event->getRequest()->willReturn($request->reveal()); $event->isMasterRequest()->willReturn(true); - $this->themeContext->setTheme( - $this->themeRepository->findOneByName($this->theme) - )->shouldBeCalled(); + $this->themeRepository->findOneByName('theme/name') + ->shouldBeCalled() + ->willReturn($this->theme->reveal()); $this->listener->setActiveThemeOnRequest($event->reveal()); + + $this->assertSame($this->theme->reveal(), $this->themeContext->getTheme()); } public function testEventListenerNotMaster(): void @@ -88,11 +92,13 @@ public function testEventListenerNotMaster(): void $event->getRequest()->willReturn($request->reveal()); $event->isMasterRequest()->willReturn(false); - $this->themeContext->setTheme( - $this->themeRepository->findOneByName($this->theme) - )->shouldBeCalled(); + $this->themeRepository->findOneByName('theme/name') + ->shouldBeCalled() + ->willReturn($this->theme->reveal()); $this->listener->setActiveThemeOnRequest($event->reveal()); + + $this->assertSame($this->theme->reveal(), $this->themeContext->getTheme()); } public function testEventListenerNoWebspace(): void @@ -106,11 +112,12 @@ public function testEventListenerNoWebspace(): void $event->getRequest()->willReturn($request->reveal()); $event->isMasterRequest()->willReturn(true); - $this->themeContext->setTheme( - $this->themeRepository->findOneByName($this->theme) - )->shouldNotBeCalled(); + $this->themeRepository->findOneByName('theme/name') + ->shouldNotBeCalled(); $this->listener->setActiveThemeOnRequest($event->reveal()); + + $this->assertNull($this->themeContext->getTheme()); } public function testEventListenerNoAttributes(): void @@ -122,11 +129,12 @@ public function testEventListenerNoAttributes(): void $event->getRequest()->willReturn($request->reveal()); $event->isMasterRequest()->willReturn(true); - $this->themeContext->setTheme( - $this->themeRepository->findOneByName($this->theme) - )->shouldNotBeCalled(); + $this->themeRepository->findOneByName('theme/name') + ->shouldNotBeCalled(); $this->listener->setActiveThemeOnRequest($event->reveal()); + + $this->assertNull($this->themeContext->getTheme()); } public function testEventListenerOnPreview(): void @@ -134,12 +142,14 @@ public function testEventListenerOnPreview(): void $attributes = $this->prophesize(RequestAttributes::class); $attributes->getAttribute('webspace', null)->willReturn($this->webspace->reveal()); - $this->themeContext->setTheme( - $this->themeRepository->findOneByName($this->theme) - )->shouldBeCalled(); + $this->themeRepository->findOneByName('theme/name') + ->shouldBeCalled() + ->willReturn($this->theme->reveal()); $this->listener->setActiveThemeOnPreviewPreRender( new PreRenderEvent($attributes->reveal()) ); + + $this->assertSame($this->theme->reveal(), $this->themeContext->getTheme()); } } diff --git a/Tests/Unit/StructureProvider/WebspaceStructureProviderTest.php b/Tests/Unit/StructureProvider/WebspaceStructureProviderTest.php deleted file mode 100644 index 832cbc7..0000000 --- a/Tests/Unit/StructureProvider/WebspaceStructureProviderTest.php +++ /dev/null @@ -1,124 +0,0 @@ -generateStructure('t1', 'MyBundle:default:t1'), - $this->generateStructure('t2', 'MyBundle:default:t2'), - $this->generateStructure('t3', 'MyBundle:default:t3'), - ]; - - $theme = 'test'; - - $webspace = $this->prophesize('Sulu\Component\Webspace\Webspace'); - $webspace->getTheme()->willReturn($theme); - - $twigLoader = $this->prophesize('\Twig_ExistsLoaderInterface'); - $twigLoader->exists('MyBundle:default:t1.html.twig')->willReturn(false); - $twigLoader->exists('MyBundle:default:t2.html.twig')->willReturn(true)->shouldBeCalled(); - $twigLoader->exists('MyBundle:default:t3.html.twig')->willReturn(false); - - $twig = $this->prophesize('\Twig_Environment'); - $twig->getLoader()->willReturn($twigLoader->reveal()); - - $structureManager = $this->prophesize('Sulu\Component\Content\Compat\StructureManagerInterface'); - $structureManager->getStructures()->willReturn($structures); - - $webspaceManager = $this->prophesize('Sulu\Component\Webspace\Manager\WebspaceManagerInterface'); - $webspaceManager->findWebspaceByKey('sulu_io')->willReturn($webspace->reveal()); - - $activeTheme = $this->prophesize('Liip\ThemeBundle\ActiveTheme'); - $activeTheme->getName()->willReturn('before'); - $activeTheme->setName('test')->shouldBeCalled(); - $activeTheme->setName('before')->shouldBeCalled(); - - $structureProvider = new WebspaceStructureProvider( - $twig->reveal(), - $structureManager->reveal(), - $cache, - $webspaceManager->reveal(), - $activeTheme->reveal() - ); - - $result = $structureProvider->getStructures('sulu_io'); - - $this->assertCount(1, $result); - $this->assertEquals($structures[1], $result[0]); - - $this->assertTrue($cache->contains('sulu_io')); - $this->assertEquals(['t2'], $cache->fetch('sulu_io')); - } - - public function testGetStructuresCached(): void - { - $cache = new ArrayCache(); - $cache->save('sulu_io', ['t1', 't3']); - - $structures = [ - $this->generateStructure('t1', 'MyBundle:default:t1'), - $this->generateStructure('t2', 'MyBundle:default:t2'), - $this->generateStructure('t3', 'MyBundle:default:t3'), - ]; - - $twig = $this->prophesize('\Twig_Environment'); - $twig->getLoader()->shouldNotBeCalled(); - - $structureManager = $this->prophesize('Sulu\Component\Content\Compat\StructureManagerInterface'); - $structureManager->getStructures()->shouldNotBeCalled(); - $structureManager->getStructure('t1')->willReturn($structures[0]); - $structureManager->getStructure('t2')->shouldNotBeCalled(); - $structureManager->getStructure('t3')->willReturn($structures[2]); - - $webspaceManager = $this->prophesize('Sulu\Component\Webspace\Manager\WebspaceManagerInterface'); - $webspaceManager->findWebspaceByKey('sulu_io')->shouldNotBeCalled(); - - $activeTheme = $this->prophesize('Liip\ThemeBundle\ActiveTheme'); - $activeTheme->getName()->shouldNotBeCalled(); - $activeTheme->setName('test')->shouldNotBeCalled(); - $activeTheme->setName('before')->shouldNotBeCalled(); - - $structureProvider = new WebspaceStructureProvider( - $twig->reveal(), - $structureManager->reveal(), - $cache, - $webspaceManager->reveal(), - $activeTheme->reveal() - ); - - $result = $structureProvider->getStructures('sulu_io'); - - $this->assertCount(2, $result); - $this->assertEquals($structures[0]->getKey(), $result[0]->getKey()); - $this->assertEquals($structures[2]->getKey(), $result[1]->getKey()); - } - - private function generateStructure(string $key, string $view): StructureInterface - { - $mock = $this->prophesize('Sulu\Component\Content\Compat\Structure\PageBridge'); - - $mock->getKey()->willReturn($key); - $mock->getView()->willReturn($view); - - return $mock->reveal(); - } -} diff --git a/composer.json b/composer.json index 02383c1..4b154e9 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "sulu/theme-bundle", "type": "sulu-bundle", - "description": "The Sulu Bundle which provides themes", + "description": "The Sulu Bundle which provides theming functionality.", "license": "MIT", "keywords": [ "sulu", @@ -14,27 +14,24 @@ } ], "require": { - "php": "^7.2", + "php": "^7.3", "sulu/sulu": "^2.0", - "symfony/config": "^5.1", - "symfony/dependency-injection": "^5.1", - "symfony/http-kernel": "^5.1", + "symfony/config": "^4.4 || ^5.0", + "symfony/dependency-injection": "^4.4 || ^5.0", + "symfony/http-kernel": "^4.4 || ^5.0", "sylius/theme-bundle": "^2.0" }, "require-dev": { "jackalope/jackalope-doctrine-dbal": "^1.3", + "symfony/dotenv": "^4.4 || ^5.0", "phpunit/phpunit": "^8.0", "jangregor/phpstan-prophecy": "^0.8", "phpstan/phpstan": "^0.12", "phpstan/phpstan-doctrine": "^0.12", "phpstan/phpstan-phpunit": "^0.12", "phpstan/phpstan-symfony": "^0.12", - "symfony/dotenv": "^5.1", "thecodingmachine/phpstan-strict-rules": "^0.12" }, - "conflict": { - "liip/theme-bundle": "1.6.0" - }, "autoload": { "psr-4": { "Sulu\\Bundle\\ThemeBundle\\": "" From 6f48444c2990af5c310c015b1af0c8e8571cdc6e Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 11 Nov 2020 16:36:29 +0100 Subject: [PATCH 08/15] Add phpunit-bridge --- .../SetThemeEventListenerTest.php | 65 ++++++++++++------- composer.json | 5 +- phpunit.xml.dist | 10 +++ 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/Tests/Unit/EventListener/SetThemeEventListenerTest.php b/Tests/Unit/EventListener/SetThemeEventListenerTest.php index 411a888..b7b5f5c 100644 --- a/Tests/Unit/EventListener/SetThemeEventListenerTest.php +++ b/Tests/Unit/EventListener/SetThemeEventListenerTest.php @@ -35,16 +35,6 @@ class SetThemeEventListenerTest extends TestCase */ private $themeContext; - /** - * @var Webspace|ObjectProphecy - */ - private $webspace; - - /** - * @var ThemeInterface|ObjectProphecy - */ - private $theme; - /** * @var SetThemeEventListener */ @@ -53,61 +43,81 @@ class SetThemeEventListenerTest extends TestCase public function setUp(): void { $this->themeRepository = $this->prophesize(ThemeRepositoryInterface::class); - $this->theme = $this->prophesize(ThemeInterface::class); $this->themeContext = new SettableThemeContext(); - $this->webspace = $this->prophesize(Webspace::class); - $this->webspace->getTheme()->willReturn('theme/name'); $this->listener = new SetThemeEventListener($this->themeRepository->reveal(), $this->themeContext); } public function testEventListener(): void { + /** @var Webspace|ObjectProphecy webspace */ + $webspace = $this->prophesize(Webspace::class); + $webspace->getTheme()->willReturn('theme/name'); + + /** @var ThemeInterface|ObjectProphecy $theme */ + $theme = $this->prophesize(ThemeInterface::class); + + /** @var Request|ObjectProphecy $request */ $request = $this->prophesize(Request::class); + /** @var RequestAttributes|ObjectProphecy $attributes */ $attributes = $this->prophesize(RequestAttributes::class); - $attributes->getAttribute('webspace')->willReturn($this->webspace->reveal()); + $attributes->getAttribute('webspace')->willReturn($webspace->reveal()); $request->get('_sulu')->willReturn($attributes->reveal()); + /** @var RequestEvent|ObjectProphecy $event */ $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request->reveal()); $event->isMasterRequest()->willReturn(true); $this->themeRepository->findOneByName('theme/name') ->shouldBeCalled() - ->willReturn($this->theme->reveal()); + ->willReturn($theme->reveal()); $this->listener->setActiveThemeOnRequest($event->reveal()); - $this->assertSame($this->theme->reveal(), $this->themeContext->getTheme()); + $this->assertSame($theme->reveal(), $this->themeContext->getTheme()); } public function testEventListenerNotMaster(): void { + /** @var Webspace|ObjectProphecy webspace */ + $webspace = $this->prophesize(Webspace::class); + $webspace->getTheme()->willReturn('theme/name'); + + /** @var ThemeInterface|ObjectProphecy $theme */ + $theme = $this->prophesize(ThemeInterface::class); + + /** @var Request|ObjectProphecy $request */ $request = $this->prophesize(Request::class); + /** @var RequestAttributes|ObjectProphecy $attributes */ $attributes = $this->prophesize(RequestAttributes::class); - $attributes->getAttribute('webspace')->willReturn($this->webspace->reveal()); + $attributes->getAttribute('webspace')->willReturn($webspace->reveal()); $request->get('_sulu')->willReturn($attributes->reveal()); + /** @var RequestEvent|ObjectProphecy $event */ $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request->reveal()); $event->isMasterRequest()->willReturn(false); $this->themeRepository->findOneByName('theme/name') ->shouldBeCalled() - ->willReturn($this->theme->reveal()); + ->willReturn($theme->reveal()); $this->listener->setActiveThemeOnRequest($event->reveal()); - $this->assertSame($this->theme->reveal(), $this->themeContext->getTheme()); + $this->assertSame($theme->reveal(), $this->themeContext->getTheme()); } public function testEventListenerNoWebspace(): void { + /** @var Request|ObjectProphecy $request */ $request = $this->prophesize(Request::class); + /** @var RequestAttributes|ObjectProphecy $attributes */ $attributes = $this->prophesize(RequestAttributes::class); $attributes->getAttribute('webspace')->willReturn(null); $request->get('_sulu')->willReturn($attributes->reveal()); + /** @var RequestEvent|ObjectProphecy $event */ $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request->reveal()); $event->isMasterRequest()->willReturn(true); @@ -122,9 +132,12 @@ public function testEventListenerNoWebspace(): void public function testEventListenerNoAttributes(): void { + /** @var Request|ObjectProphecy $request */ $request = $this->prophesize(Request::class); + /* @var RequestAttributes|ObjectProphecy $attributes */ $request->get('_sulu')->willReturn(null); + /** @var RequestEvent|ObjectProphecy $event */ $event = $this->prophesize(RequestEvent::class); $event->getRequest()->willReturn($request->reveal()); $event->isMasterRequest()->willReturn(true); @@ -139,17 +152,25 @@ public function testEventListenerNoAttributes(): void public function testEventListenerOnPreview(): void { + /** @var ThemeInterface|ObjectProphecy $theme */ + $theme = $this->prophesize(ThemeInterface::class); + + /** @var Webspace|ObjectProphecy webspace */ + $webspace = $this->prophesize(Webspace::class); + $webspace->getTheme()->willReturn('theme/name'); + + /** @var RequestAttributes|ObjectProphecy $attributes */ $attributes = $this->prophesize(RequestAttributes::class); - $attributes->getAttribute('webspace', null)->willReturn($this->webspace->reveal()); + $attributes->getAttribute('webspace', null)->willReturn($webspace->reveal()); $this->themeRepository->findOneByName('theme/name') ->shouldBeCalled() - ->willReturn($this->theme->reveal()); + ->willReturn($theme->reveal()); $this->listener->setActiveThemeOnPreviewPreRender( new PreRenderEvent($attributes->reveal()) ); - $this->assertSame($this->theme->reveal(), $this->themeContext->getTheme()); + $this->assertSame($theme->reveal(), $this->themeContext->getTheme()); } } diff --git a/composer.json b/composer.json index 4b154e9..9aa9a3e 100644 --- a/composer.json +++ b/composer.json @@ -24,13 +24,14 @@ "require-dev": { "jackalope/jackalope-doctrine-dbal": "^1.3", "symfony/dotenv": "^4.4 || ^5.0", - "phpunit/phpunit": "^8.0", + "phpunit/phpunit": "^8.5.9", "jangregor/phpstan-prophecy": "^0.8", "phpstan/phpstan": "^0.12", "phpstan/phpstan-doctrine": "^0.12", "phpstan/phpstan-phpunit": "^0.12", "phpstan/phpstan-symfony": "^0.12", - "thecodingmachine/phpstan-strict-rules": "^0.12" + "thecodingmachine/phpstan-strict-rules": "^0.12", + "symfony/phpunit-bridge": "^5.1" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8aac5b0..5473388 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,4 +16,14 @@ + + + + + + + + + + From e3b8e9a307a122a0f7e5564ba55d035f0eb6f7eb Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 12 Nov 2020 09:38:55 +0100 Subject: [PATCH 09/15] Add UPGRADE.md file --- README.md | 2 +- UPGRADE.md | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 UPGRADE.md diff --git a/README.md b/README.md index 66d9be8..d2832e7 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ [![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 package enables a basic theming for sulu. It uses [Sylius/SyliusThemeBundle](https://github.com/Sylius/SyliusThemeBundle) to extend the discovery feature of twig. diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 0000000..9f53605 --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,94 @@ +# Upgrade + +## 2.1 + +### Switch from LiipThemeBundle to SyliusThemeBundle +To achieve Symfony 5 compatibility the ThemingBundle has to be changed from [LiipThemeBundle](https://github.com/liip/LiipThemeBundle) to [SyliusThemeBundle](https://github.com/Sylius/SyliusThemeBundle). + +#### Remove the old theme bundle and install the SyliusThemeBundle: +```bash +# Remove old theme-bundle +composer remove liip/theme-bundle --no-update + +# Install new theme-bundle +composer require sylius/theme-bundle +``` + +#### Configure the SyliusThemeBundle: +In order you to use the bundle you have to add the following default configuration: +```yaml +# ./config/packages/sylius_theme.yaml + +sylius_theme: + sources: + filesystem: ~ +``` +By default the bundle seeks for the themes in the `%kernel.project_dir%/themes` directory. This can be changed via the +yaml configuration: +```yaml +sylius_theme: + sources: + filesystem: + filename: theme.json #default is composer.json + directories: + - "%kernel.project_dir%/templates/themes" +``` + +#### Theme Configuration +Every theme must have its own configuration file in form of a `composer.json`. +Go to https://github.com/Sylius/SyliusThemeBundle/blob/master/docs/theme_configuration_reference.md for detailed +documentation about the configuration options. The configuration file has to be placed in the specified directory +of the `sylius_theme.yaml`. + +The minimal configuration for a theme would be the following: +```json +// ./templates/themes//theme.json + +{ + "name": "vendor/name" +} +```` +It is important, that the `name` matches the naming convention of composer. + +If your old theme name didn't match the naming convention you also have to change it in the `webspace.xml` to the new one. +```xml + + + example.com + example + ... + vendor/name + ... + +``` + +#### Update project structure +Your themes have to be placed in a `templates` folder next to the `theme.json` file. + +For example: `%kernel.project_dir%/templates/themes//templates` + +This results in the following project structure: + +``` +ProjectName +├── composer.json +├── assets +├── bin +├── config +├── ... +├── templates +│ ├── themes +│ │ ├── +│ │ │ ├── templates +│ │ │ │ └── base.html.twig +│ │ │ └── theme.json +│ │ └── +│ │ ├── templates +│ │ │ └── base.html.twig +│ │ └── theme.json +| └── base.html.twig +├── ... +└── ... +``` From 9253c8f82c2332cffda1430b5b80cbeadc802f23 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 12 Nov 2020 10:20:35 +0100 Subject: [PATCH 10/15] Add empty lines after headlines --- UPGRADE.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/UPGRADE.md b/UPGRADE.md index 9f53605..ca9aa0c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -3,9 +3,11 @@ ## 2.1 ### Switch from LiipThemeBundle to SyliusThemeBundle + To achieve Symfony 5 compatibility the ThemingBundle has to be changed from [LiipThemeBundle](https://github.com/liip/LiipThemeBundle) to [SyliusThemeBundle](https://github.com/Sylius/SyliusThemeBundle). #### Remove the old theme bundle and install the SyliusThemeBundle: + ```bash # Remove old theme-bundle composer remove liip/theme-bundle --no-update @@ -15,7 +17,9 @@ composer require sylius/theme-bundle ``` #### Configure the SyliusThemeBundle: + In order you to use the bundle you have to add the following default configuration: + ```yaml # ./config/packages/sylius_theme.yaml @@ -23,8 +27,10 @@ sylius_theme: sources: filesystem: ~ ``` + By default the bundle seeks for the themes in the `%kernel.project_dir%/themes` directory. This can be changed via the yaml configuration: + ```yaml sylius_theme: sources: @@ -35,22 +41,26 @@ sylius_theme: ``` #### Theme Configuration + Every theme must have its own configuration file in form of a `composer.json`. Go to https://github.com/Sylius/SyliusThemeBundle/blob/master/docs/theme_configuration_reference.md for detailed documentation about the configuration options. The configuration file has to be placed in the specified directory of the `sylius_theme.yaml`. The minimal configuration for a theme would be the following: + ```json // ./templates/themes//theme.json { "name": "vendor/name" } -```` +``` + It is important, that the `name` matches the naming convention of composer. If your old theme name didn't match the naming convention you also have to change it in the `webspace.xml` to the new one. + ```xml /templates` From 4526b1f5114424cf836d682771ced90e0c49d394 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 12 Nov 2020 11:57:53 +0100 Subject: [PATCH 11/15] Update README.md --- README.md | 156 ++++++++++++++++++++++++++++++++++++++++++++++- UPGRADE.md | 76 +++++++++++++---------- phpunit.xml.dist | 2 +- 3 files changed, 197 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index d2832e7..65fd784 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,155 @@ -# SuluThemeBundle +

SuluThemeBundle

-[![Build Status](https://travis-ci.org/sulu/SuluThemeBundle.svg?branch=develop)](https://travis-ci.org/sulu/SuluThemeBundle) +

+ + Official Sulu Bundle Badge + +

-This package enables a basic theming for sulu. It uses [Sylius/SyliusThemeBundle](https://github.com/Sylius/SyliusThemeBundle) to extend the discovery feature of twig. +

+ + GitHub tag (latest SemVer) + + + GitHub license + + + Sulu compatibility + +

+
+ +The **SuluThemeBundle** provides the functionality to add multiple themes for different look and feel using multiple +webspaces in the [Sulu](https://sulu.io/) content management system. + +To achieve this, the bundle uses the [SyliusThemeBundle](https://github.com/Sylius/SyliusThemeBundle) to render different +twig templates and asset files. Each webspace can have it's own theme. + +## 🚀  Installation and Usage + +### Install the bundle + +Execute the following [composer](https://getcomposer.org/) command to add the bundle to the dependencies of your +project: + +```bash +composer require sulu/theme-bundle +``` + +### Enable the bundle + +Enable the bundle by adding it to the list of registered bundles in the `config/bundles.php` file of your project: + +```php +return [ + /* ... */ + Sulu\Bundle\ThemeBundle\SuluThemeBundle::class => ['all' => true], +]; +``` + + +### Configure the SyliusThemeBundle + +In order to use the bundle you have to add at least the following default configuration: + +```yaml +# ./config/packages/sylius_theme.yaml + +sylius_theme: + sources: + filesystem: ~ +``` + +By default the bundle seeks for the themes in the `%kernel.project_dir%/themes` directory. This can be changed via the +yaml configuration: + +```yaml +sylius_theme: + sources: + filesystem: + filename: theme.json #default is composer.json + directories: + - "%kernel.project_dir%/templates/themes" +``` + +For more detailed information about the configuration sources go to the [Sylius documentation](https://github.com/Sylius/SyliusThemeBundle/blob/master/docs/configuration_sources.md). + +### Configure your themes + +Every theme must have its own configuration file in form of a `composer.json`. +Go to the [Theme Configuration Reference](https://github.com/Sylius/SyliusThemeBundle/blob/master/docs/theme_configuration_reference.md) +for the detailed documentation about the configuration options. +The configuration file has to be placed in the specified directory of the `sylius_theme.yaml`. + +The minimal configuration for a theme would be the following: + +```json +// ./templates/themes//theme.json + +{ + "name": "vendor/" +} +``` + +It is important, that the `name` matches the naming convention of composer. + +### Create a theme +To create a theme you have to create a new directory in the templates/themes folder of your application with the name of +the new theme. In the newly created directory you have to add the theme configuration file `theme.json`. +See [Configure your themes](#configure-your-themes). Additonally you have to create the `templates` directory next to +the `theme.json`. Afterwards you have to fill this folder with all the used templates in the webspace. + +This results in the following project structure: + +``` +ProjectName +├── composer.json +├── assets +├── bin +├── config +├── ... +├── templates +│ ├── themes +│ │ ├── +│ │ │ ├── templates +│ │ │ │ └── base.html.twig +│ │ │ └── theme.json +│ │ └── +│ │ ├── templates +│ │ │ └── base.html.twig +│ │ └── theme.json +| └── base.html.twig +├── ... +└── ... +``` + +### Add one of your themes to a webspace +Each webspace can use a different theme. A theme can be enabled for a specific webspace by adding the theme-name +`vendor/theme-name` to your webspace: + +```xml + + + example.com + example + ... + vendor/theme-name + ... + +``` + +## ❤️  Support and Contributions + +The Sulu content management system is a **community-driven open source project** backed by various partner companies. +We are committed to a fully transparent development process and **highly appreciate any contributions**. + +In case you have questions, we are happy to welcome you in our official [Slack channel](https://sulu.io/services-and-support). +If you found a bug or miss a specific feature, feel free to **file a new issue** with a respective title and description +on the the [sulu/SuluThemeBundle](https://github.com/sulu/SuluThemeBundle) repository. + + +## 📘  License + +The Sulu content management system is released under the under terms of the [MIT License](LICENSE). diff --git a/UPGRADE.md b/UPGRADE.md index ca9aa0c..b8b976d 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,6 +1,6 @@ # Upgrade -## 2.1 +## 3.0 ### Switch from LiipThemeBundle to SyliusThemeBundle @@ -13,12 +13,25 @@ To achieve Symfony 5 compatibility the ThemingBundle has to be changed from [Lii composer remove liip/theme-bundle --no-update # Install new theme-bundle -composer require sylius/theme-bundle +composer require sylius/theme-bundle:"^2.0" --no-update +composer require sulu/theme-bundle:"^3.0" ``` +#### Remove old configuration + +The old `liip_theme.yaml` configuration needs to be removed: + +```diff +- liip_theme: +- themes: ['project', 'awesome'] +- active_theme: 'awesome' +``` + +In the next step you see how you configure the **awesome** theme using the SyliusThemeBundle. + #### Configure the SyliusThemeBundle: -In order you to use the bundle you have to add the following default configuration: +In order to use the bundle you have to add the following default configuration: ```yaml # ./config/packages/sylius_theme.yaml @@ -28,7 +41,7 @@ sylius_theme: filesystem: ~ ``` -By default the bundle seeks for the themes in the `%kernel.project_dir%/themes` directory. This can be changed via the +By default, the bundle seeks for the themes in the `%kernel.project_dir%/themes` directory. This can be changed via the yaml configuration: ```yaml @@ -40,43 +53,28 @@ sylius_theme: - "%kernel.project_dir%/templates/themes" ``` -#### Theme Configuration - -Every theme must have its own configuration file in form of a `composer.json`. -Go to https://github.com/Sylius/SyliusThemeBundle/blob/master/docs/theme_configuration_reference.md for detailed -documentation about the configuration options. The configuration file has to be placed in the specified directory -of the `sylius_theme.yaml`. +#### Convert Theme Configuration -The minimal configuration for a theme would be the following: +In the SyliusThemeBundle every theme must have its own configuration file in form of a `composer.json`. +Add a `theme.json` file and add the following minimal configuration: -```json -// ./templates/themes//theme.json - -{ - "name": "vendor/name" -} +```diff ++ { ++ "name": "app/awesome" ++ } ``` -It is important, that the `name` matches the naming convention of composer. +Go to the [Theme Configuration Reference](https://github.com/Sylius/SyliusThemeBundle/blob/master/docs/theme_configuration_reference.md) +for the detailed documentation about the configuration options. -If your old theme name didn't match the naming convention you also have to change it in the `webspace.xml` to the new one. +Most likely you have to change the theme name. It is important, that the `name` matches the naming convention of composer (`vendor/name`). +Furthermore the `theme.json` has to be moved into the directory for this specific theme. -```xml - - - example.com - example - ... - vendor/name - ... - -``` +For example: `%kernel.project_dir%/templates/themes/awesome/theme.json` #### Update project structure -Your themes have to be placed in a `templates` folder next to the `theme.json` file. +Your templates have to be placed in a `templates` directory next to the `theme.json` file. For example: `%kernel.project_dir%/templates/themes//templates` @@ -91,7 +89,7 @@ ProjectName ├── ... ├── templates │ ├── themes -│ │ ├── +│ │ ├── awesome │ │ │ ├── templates │ │ │ │ └── base.html.twig │ │ │ └── theme.json @@ -103,3 +101,15 @@ ProjectName ├── ... └── ... ``` + +As you can see in the project structure, each theme must have their own `theme.json` configuration file next to the +templates directory. + +#### Update webspace configuration + +If your old theme name didn't match the naming convention you also have to change it in the `webspace.xml` to the new one. + +```diff +- awesome ++ app/awesome +``` diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5473388..f7f0df6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,7 +18,7 @@ - + From 32f01d279a1e6c4858592e07ef135205f7ec4871 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 12 Nov 2020 14:28:05 +0100 Subject: [PATCH 12/15] Update template path in readme and update.md --- README.md | 44 ++++++++++++++++++++------------------------ UPGRADE.md | 32 ++++++++++++++------------------ 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 65fd784..3bc99ca 100644 --- a/README.md +++ b/README.md @@ -60,16 +60,14 @@ sylius_theme: filesystem: ~ ``` -By default the bundle seeks for the themes in the `%kernel.project_dir%/themes` directory. This can be changed via the -yaml configuration: +By default, the bundle seeks for the themes in the `%kernel.project_dir%/themes` directory and looks for a configuration +file named `composer.json`. This can be changed via the yaml configuration: ```yaml sylius_theme: sources: filesystem: - filename: theme.json #default is composer.json - directories: - - "%kernel.project_dir%/templates/themes" + filename: theme.json ``` For more detailed information about the configuration sources go to the [Sylius documentation](https://github.com/Sylius/SyliusThemeBundle/blob/master/docs/configuration_sources.md). @@ -79,25 +77,25 @@ For more detailed information about the configuration sources go to the [Sylius Every theme must have its own configuration file in form of a `composer.json`. Go to the [Theme Configuration Reference](https://github.com/Sylius/SyliusThemeBundle/blob/master/docs/theme_configuration_reference.md) for the detailed documentation about the configuration options. -The configuration file has to be placed in the specified directory of the `sylius_theme.yaml`. The minimal configuration for a theme would be the following: ```json -// ./templates/themes//theme.json +// ./themes//theme.json { - "name": "vendor/" + "name": "vendor/" } ``` -It is important, that the `name` matches the naming convention of composer. +It is important, that the `name` matches the naming convention of composer (`vendor/name`). ### Create a theme -To create a theme you have to create a new directory in the templates/themes folder of your application with the name of -the new theme. In the newly created directory you have to add the theme configuration file `theme.json`. +First you have to create the directory `themes` inside your project. +To create a theme you have to create a new directory in the themes folder with the name of the new theme. +In the newly created directory you have to add the theme configuration file `theme.json`. See [Configure your themes](#configure-your-themes). Additonally you have to create the `templates` directory next to -the `theme.json`. Afterwards you have to fill this folder with all the used templates in the webspace. +the `theme.json`. Afterwards you have to fill this folder with all the used templates and assets for this theme. This results in the following project structure: @@ -107,24 +105,22 @@ ProjectName ├── assets ├── bin ├── config -├── ... ├── templates -│ ├── themes -│ │ ├── -│ │ │ ├── templates -│ │ │ │ └── base.html.twig -│ │ │ └── theme.json -│ │ └── -│ │ ├── templates -│ │ │ └── base.html.twig -│ │ └── theme.json -| └── base.html.twig +├── themes +│ ├── +│ │ ├── templates +│ │ │ └── base.html.twig +│ │ └── theme.json +│ └── +│ ├── templates +│ │ └── base.html.twig +│ └── theme.json ├── ... └── ... ``` ### Add one of your themes to a webspace -Each webspace can use a different theme. A theme can be enabled for a specific webspace by adding the theme-name +Each webspace can use a different theme. A theme can be enabled for a specific webspace by adding the theme name `vendor/theme-name` to your webspace: ```xml diff --git a/UPGRADE.md b/UPGRADE.md index b8b976d..ac2f16e 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -41,16 +41,14 @@ sylius_theme: filesystem: ~ ``` -By default, the bundle seeks for the themes in the `%kernel.project_dir%/themes` directory. This can be changed via the -yaml configuration: +By default, the bundle seeks for the themes in the `%kernel.project_dir%/themes` directory and looks for a configuration +file named `composer.json`. This can be changed via the yaml configuration: ```yaml sylius_theme: sources: filesystem: - filename: theme.json #default is composer.json - directories: - - "%kernel.project_dir%/templates/themes" + filename: theme.json ``` #### Convert Theme Configuration @@ -70,13 +68,13 @@ for the detailed documentation about the configuration options. Most likely you have to change the theme name. It is important, that the `name` matches the naming convention of composer (`vendor/name`). Furthermore the `theme.json` has to be moved into the directory for this specific theme. -For example: `%kernel.project_dir%/templates/themes/awesome/theme.json` +For example: `%kernel.project_dir%/themes/awesome/theme.json` #### Update project structure Your templates have to be placed in a `templates` directory next to the `theme.json` file. -For example: `%kernel.project_dir%/templates/themes//templates` +For example: `%kernel.project_dir%/themes//templates` This results in the following project structure: @@ -86,18 +84,16 @@ ProjectName ├── assets ├── bin ├── config -├── ... ├── templates -│ ├── themes -│ │ ├── awesome -│ │ │ ├── templates -│ │ │ │ └── base.html.twig -│ │ │ └── theme.json -│ │ └── -│ │ ├── templates -│ │ │ └── base.html.twig -│ │ └── theme.json -| └── base.html.twig +├── themes +│ ├── awesome +│ │ ├── templates +│ │ │ └── base.html.twig +│ │ └── theme.json +│ └── +│ ├── templates +│ │ └── base.html.twig +│ └── theme.json ├── ... └── ... ``` From 6a99b8eedd438dc718c465d02c7237ba1f6d0c47 Mon Sep 17 00:00:00 2001 From: Prokyonn Date: Thu, 12 Nov 2020 15:33:25 +0100 Subject: [PATCH 13/15] Apply suggestions from code review Co-authored-by: nnatter --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3bc99ca..2755e75 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ sylius_theme: filesystem: ~ ``` -By default, the bundle seeks for the themes in the `%kernel.project_dir%/themes` directory and looks for a configuration -file named `composer.json`. This can be changed via the yaml configuration: +By default, the bundle seeks for the themes in the `%kernel.project_dir%/themes` directory and looks for a +theme configuration file named `composer.json`. This can be changed via the yaml configuration: ```yaml sylius_theme: @@ -70,7 +70,7 @@ sylius_theme: filename: theme.json ``` -For more detailed information about the configuration sources go to the [Sylius documentation](https://github.com/Sylius/SyliusThemeBundle/blob/master/docs/configuration_sources.md). +For more detailed information about the configuration sources go to the [SyliusThemeBundle documentation](https://github.com/Sylius/SyliusThemeBundle/blob/master/docs/configuration_sources.md). ### Configure your themes From b9bac6894713c40227edc27bd23be77b03db6974 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 12 Nov 2020 15:35:26 +0100 Subject: [PATCH 14/15] Fix theme configuration file name --- README.md | 2 +- UPGRADE.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2755e75..bf2bb15 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ For more detailed information about the configuration sources go to the [SyliusT ### Configure your themes -Every theme must have its own configuration file in form of a `composer.json`. +Every theme must have its own configuration file in form of a `theme.json`. Go to the [Theme Configuration Reference](https://github.com/Sylius/SyliusThemeBundle/blob/master/docs/theme_configuration_reference.md) for the detailed documentation about the configuration options. diff --git a/UPGRADE.md b/UPGRADE.md index ac2f16e..0487b85 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -53,7 +53,7 @@ sylius_theme: #### Convert Theme Configuration -In the SyliusThemeBundle every theme must have its own configuration file in form of a `composer.json`. +In the SyliusThemeBundle every theme must have its own configuration file in form of a `theme.json`. Add a `theme.json` file and add the following minimal configuration: ```diff From 1049812e1796875ac71696fde6c1c7827b102233 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 19 Nov 2020 11:07:07 +0100 Subject: [PATCH 15/15] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bf2bb15..2d39b6d 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,7 @@ ProjectName ``` ### Add one of your themes to a webspace + Each webspace can use a different theme. A theme can be enabled for a specific webspace by adding the theme name `vendor/theme-name` to your webspace: