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

Add abandoned note and upgrade to sylius theme bundle #204

Merged
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
145 changes: 145 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Theme Bundle
============

> This project is not longer maintained and recommends to use [SyliusThemeBundle](https://github.com/Sylius/SyliusThemeBundle) instead for support of Symfony 5 and Twig 3.
> For migration have a look at [Migrate to SyliusThemeBundle](#migrate-to-syliusthemebundle).

This bundle provides you the possibility to add themes to each bundle. In your
bundle directory it will look under `Resources/themes/<themename>` or fall back
to the normal Resources/views if no matching file was found.
Expand Down Expand Up @@ -304,6 +307,148 @@ liip_theme:
device_detection: my_devcice_detection
````

## Migrate to SyliusThemeBundle

This will show you the stepts to switch from the [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:"^2.0"
```

#### Remove old configuration

The old `liip_theme.yaml` configuration needs to be removed:

```diff
-liip_theme:
- themes: ['awesome']
- active_theme: 'awesome'
```

In the next step you see how you configure the **awesome** theme using the SyliusThemeBundle.

#### Configure the SyliusThemeBundle:

In order 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 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
```

#### Convert Theme Configuration

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
{
"name": "app/awesome"
}
```

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.

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%/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%/themes/<theme-name>/templates`

This results in the following project structure:

```
ProjectName
├── composer.json
├── assets
├── bin
├── config
├── templates
├── themes
│ ├── awesome
│ │ ├── templates
│ │ │ └── base.html.twig
│ │ └── theme.json
│ └── <theme-name-2>
│ ├── templates
│ │ └── base.html.twig
│ └── theme.json
├── ...
└── ...
```

As you can see in the project structure, each theme must have their own `theme.json` configuration file next to the
templates directory.

#### Create ThemeRequestListener

You need to create a ThemeRequestListener to set the theme based on the current `$request` data:

```php
use Sylius\Bundle\ThemeBundle\Context\SettableThemeContext;
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;

final class ThemeRequestListener
{
/** @var ThemeRepositoryInterface */
private $themeRepository;

/** @var SettableThemeContext */
private $themeContext;

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

public function onKernelRequest(GetResponseEvent $event): void
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
// don't do anything if it's not the master request
return;
}

$themeName = 'app/awesome';

// here you can set the $themeName based on $event->getRequest() object

$this->themeContext->setTheme(
$this->themeRepository->findOneByName($themeName)
);
}
}
```

Have a look also at the [SyliusThemeBundle Documentation](https://github.com/Sylius/SyliusThemeBundle/tree/master/docs/index.md).

## Contribution

Active contribution and patches are very welcome. To keep things in shape we
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"conflict": {
"sebastian/comparator": "1.2.3"
},
"abandoned": "sylius/theme-bundle",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
Expand Down