Skip to content
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

[Theme] migrate to sylius/theme-bundle #1513

Merged
merged 2 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Resources/themes/test-theme/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "coreshop/test-theme"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends '@CoreShopFrontend/layout-column.html.twig' %}

{% block center %}

{% endblock %}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"gedmo/doctrine-extensions": "^2.4.12",
"jms/serializer-bundle": "^2.0",
"knplabs/knp-menu-bundle": "^2.2.0",
"liip/theme-bundle": "^1.4",
"sylius/theme-bundle": "^2.0",
"payum/offline": "^1.4",
"payum/paypal-express-checkout-nvp": "^1.4",
"payum/payum-bundle": "^2.2",
Expand Down
10 changes: 3 additions & 7 deletions src/CoreShop/Behat/Context/Domain/ThemeContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,29 @@

use Behat\Behat\Context\Context;
use CoreShop\Behat\Service\SharedStorageInterface;
use CoreShop\Bundle\ThemeBundle\Service\ActiveThemeInterface;
use CoreShop\Bundle\ThemeBundle\Service\ThemeResolverInterface;
use Webmozart\Assert\Assert;

final class ThemeContext implements Context
{
private $sharedStorage;
private $themeResolver;
private $activeTheme;

public function __construct(
SharedStorageInterface $sharedStorage,
ThemeResolverInterface $themeResolver,
ActiveThemeInterface $activeTheme
ThemeResolverInterface $themeResolver
) {
$this->sharedStorage = $sharedStorage;
$this->themeResolver = $themeResolver;
$this->activeTheme = $activeTheme;
}

/**
* @Then /^the current theme name should be "([^"]+)"$/
*/
public function currentThemeNameIs(string $currentThemeName)
{
$this->themeResolver->resolveTheme($this->activeTheme);
$theme = $this->themeResolver->resolveTheme();

Assert::same($this->activeTheme->getActiveTheme(), $currentThemeName);
Assert::same($theme, $currentThemeName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ services:
arguments:
- '@coreshop.behat.shared_storage'
- '@coreshop.theme.resolver'
- '@CoreShop\Bundle\ThemeBundle\Service\ActiveThemeInterface'
tags:
- { name: fob.context_service }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ services:
CoreShop\Bundle\StoreBundle\Theme\StoreThemeResolver:
arguments:
- '@CoreShop\Component\Store\Context\StoreContextInterface'
- '@coreshop.repository.store'
tags:
- { name: coreshop.theme.resolver, type: coreshop_store, priority: 20 }
32 changes: 4 additions & 28 deletions src/CoreShop/Bundle/StoreBundle/Theme/StoreThemeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,30 @@

namespace CoreShop\Bundle\StoreBundle\Theme;

use CoreShop\Bundle\ThemeBundle\Service\ActiveThemeInterface;
use CoreShop\Bundle\ThemeBundle\Service\ThemeNotResolvedException;
use CoreShop\Bundle\ThemeBundle\Service\ThemeResolverInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use CoreShop\Component\Store\Context\StoreContextInterface;
use CoreShop\Component\Store\Context\StoreNotFoundException;
use CoreShop\Component\Store\Model\StoreInterface;

final class StoreThemeResolver implements ThemeResolverInterface
{
private $storeContext;
private $storeRepository;

public function __construct(
StoreContextInterface $storeContext,
RepositoryInterface $storeRepository
) {
public function __construct(StoreContextInterface $storeContext)
{
$this->storeContext = $storeContext;
$this->storeRepository = $storeRepository;
}

/**
* {@inheritdoc}
*/
public function resolveTheme(ActiveThemeInterface $activeTheme): void
public function resolveTheme(): string
{
$themes = [];

/**
* @var StoreInterface $store
*/
foreach ($this->storeRepository->findAll() as $store) {
$storeTheme = $store->getTemplate();

if ($storeTheme) {
$themes[] = $storeTheme;
}
}

$activeTheme->addThemes($themes);

try {
$store = $this->storeContext->getStore();

if ($theme = $store->getTemplate()) {
$activeTheme->setActiveTheme($theme);

return;
return $theme;
}
} catch (StoreNotFoundException $exception) {
throw new ThemeNotResolvedException($exception);
Expand Down
89 changes: 0 additions & 89 deletions src/CoreShop/Bundle/ThemeBundle/Collector/ThemeCollector.php

This file was deleted.

42 changes: 42 additions & 0 deletions src/CoreShop/Bundle/ThemeBundle/Context/ThemeContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2020 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

declare(strict_types=1);

namespace CoreShop\Bundle\ThemeBundle\Context;

use CoreShop\Bundle\ThemeBundle\Service\ThemeNotResolvedException;
use CoreShop\Bundle\ThemeBundle\Service\ThemeResolverInterface;
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface;
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;

final class ThemeContext implements ThemeContextInterface
{
private $resolver;
private $themeRepository;

public function __construct(ThemeResolverInterface $resolver, ThemeRepositoryInterface $themeRepository)
{
$this->resolver = $resolver;
$this->themeRepository = $themeRepository;
}

public function getTheme(): ?ThemeInterface
{
try {
return $this->themeRepository->findOneByName($this->resolver->resolveTheme());
} catch (ThemeNotResolvedException $exception) {
return null;
}
}
}
4 changes: 2 additions & 2 deletions src/CoreShop/Bundle/ThemeBundle/CoreShopThemeBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
namespace CoreShop\Bundle\ThemeBundle;

use CoreShop\Bundle\ThemeBundle\DependencyInjection\Compiler\CompositeThemeResolverPass;
use Liip\ThemeBundle\LiipThemeBundle;
use PackageVersions\Versions;
use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
use Pimcore\Extension\Bundle\Traits\PackageVersionTrait;
use Pimcore\HttpKernel\Bundle\DependentBundleInterface;
use Pimcore\HttpKernel\BundleCollection\BundleCollection;
use Sylius\Bundle\ThemeBundle\SyliusThemeBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class CoreShopThemeBundle extends AbstractPimcoreBundle implements DependentBundleInterface
Expand All @@ -32,7 +32,7 @@ class CoreShopThemeBundle extends AbstractPimcoreBundle implements DependentBund
*/
public static function registerDependentBundles(BundleCollection $collection)
{
$collection->addBundle(new LiipThemeBundle(), 1100);
$collection->addBundle(new SyliusThemeBundle(), 1100);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,50 +36,6 @@ public function getConfigTreeBuilder()
->booleanNode('pimcore_document_property')->defaultFalse()->end()
->end()
->end()
->arrayNode('inheritance')
->normalizeKeys(false)
->useAttributeAsKey('theme_name')
->beforeNormalization()
->always()
->then(function ($config) {
if (!\is_array($config)) {
return [];
}
// If XML config with only one routing attribute
if (2 === \count($config) && isset($config['theme_name']) && isset($config['parent_themes'])) {
$config = [0 => $config];
}

$newConfig = [];
foreach ($config as $k => $v) {
if (!\is_int($k)) {
$newConfig[$k] = [
'parent_themes' => $v['parent_themes'] ?? (\is_array($v) ? array_values($v) : [$v]),
];
} else {
$newConfig[$v['theme_name']]['parent_themes'] = array_map(
function ($a) {
return \is_string($a) ? $a : $a['service'];
},
array_values($v['parent_themes'])
);
}
}

return $newConfig;
})
->end()
->prototype('array')
->performNoDeepMerging()
->children()
->arrayNode('parent_themes')
->requiresAtLeastOneElement()
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
->end()
->end();

return $treeBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
use CoreShop\Bundle\ThemeBundle\Service\ThemeResolverInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class CoreShopThemeExtension extends Extension
Expand All @@ -35,7 +33,7 @@ public function load(array $configs, ContainerBuilder $container)
{
$config = $this->processConfiguration($this->getConfiguration([], $container), $configs);

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

if (false === $config['default_resolvers']['pimcore_site']) {
Expand All @@ -45,24 +43,7 @@ public function load(array $configs, ContainerBuilder $container)
if (false === $config['default_resolvers']['pimcore_document_property']) {
$container->removeDefinition(PimcoreDocumentPropertyResolver::class);
}

if (isset($config['inheritance']) && count($config['inheritance']) > 0) {
$container->setParameter('coreshop.theme_bundle.inheritance', $config['inheritance']);

$inheritanceLocator = new Definition(InheritanceLocator::class);
$inheritanceLocator->setArguments([
new Reference('kernel'),
new Reference('liip_theme.active_theme'),
'%kernel.root_dir%/Resources',
[],
'%liip_theme.path_patterns%',
'%coreshop.theme_bundle.inheritance%'
]);
$inheritanceLocator->setDecoratedService('liip_theme.file_locator');

$container->setDefinition(InheritanceLocator::class, $inheritanceLocator);
}


$container
->registerForAutoconfiguration(ThemeResolverInterface::class)
->addTag(CompositeThemeResolverPass::THEME_RESOLVER_TAG);
Expand Down
Loading