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

Cascading Themes? #392

Closed
adrexia opened this issue Sep 25, 2018 · 7 comments
Closed

Cascading Themes? #392

adrexia opened this issue Sep 25, 2018 · 7 comments

Comments

@adrexia
Copy link

adrexia commented Sep 25, 2018

Is it possible to use cascading themes with subsites? Or to define the allowed themes from yml? It looks like they might currently be able to be set from config.php, but it would be super handy if we could define a list of themes from yml. eg:

SilverStripe\Subsites\Model\Subsite:
  allowed_themes:
    - '/theme-default'
    - '/theme-other'

Or, if cascading needs to be defined:

SilverStripe\Subsites\Model\Subsite:
  allowed_themes:
    defaultThemeName:
       - '$public'
       - '/theme-default'
       - '$default'
    otherThemeName:
       - '$public'
       - '/theme-other'
       - '$default'
@NightJar
Copy link
Contributor

We talked on slack around how the following code sets a protected static variable in a form of memory cache that lasts the request, as opposed to config.

* @param array $themes - Numeric array of all themes which are allowed to be selected for all subsites.
*/
public static function set_allowed_themes($themes)
{
self::$allowed_themes = $themes;
}

This led to conversation opining about how this may be due to per-subsite theme restrictions.

I think it is probably because it's dynamic per subsite.
an config is not dynamic, and for all subsites.
(sic)

Am I understanding the usecase you're after here in that you'd like to have a way to set themes subsites can use globally, before then filtering that list down via the current process (allowed_themes)?

@adrexia
Copy link
Author

adrexia commented Sep 25, 2018

There doesn't seem to be an interface for setting allowed themes based on subsite, so I guess currently that would have to be hardcoded to a SubsiteID if used dynamically?

Our current use-case is to be able to define our themes (at all). Other than this module, there is no requirement with Silverstripe 4 for themes to live in a themes folder, so our themes normally don't. But on top of that, we have some cases where the subsite theme differs very little from the original theme, and it would make sense to use the cascading theme behaviour of SilverStripe 4. There are work arounds for that if we need them (e.g. moving theme templates out into a module).

One other thing to consider is that cascading themes make little sense on their own. Its only with Subsites that they start to have value.

@NightJar
Copy link
Contributor

Neat, thanks for the extra info :)

@NightJar
Copy link
Contributor

NightJar commented Apr 4, 2019

I'm going to increase the impact on this since for CWP the Watea theme would cease to function, as it relies on the cascade.

@robbieaverill
Copy link
Contributor

I think we can also call this a bug too

@ScopeyNZ
Copy link
Contributor

Ok I've looked into this a bunch.

Themes do cascade by default in subsites. The theme you choose with the dropdown available in subsites will pick a theme to be moved to the "top of the list". It will then cascade down your existing theme definitions.

I'm going to prep a patch that will basically ignore all themes defined above the theme in your themes definition when you choose a theme using the dropdown. This is a bit of stop-gap fix.

I think @adrexia's suggestion of defining cascading theme "bundles" is still really good. I like the following example configuration - we can do it in a non-breaking way - essentially defining a different way of declaring the theme dropdown. It might be better to give it a different config key though

SilverStripe\Subsites\Model\Subsite:
  allowed_themes:
    defaultThemeName:
       - '$public'
       - '/theme-default'
       - '$default'
    otherThemeName:
       - '$public'
       - '/theme-other'
       - '$default'

This is definitely an enhancement. I'll create a PR for the aforementioned patch but I'll change this back to an enhancement.

ScopeyNZ added a commit to creative-commoners/silverstripe-subsites that referenced this issue May 31, 2019
- Fixes an issue where themes would cascade "up" the list of themes
- Provides configuration for defining custom theme options with their own sets of cascading themes

Fixes silverstripe#392
ScopeyNZ added a commit to creative-commoners/silverstripe-subsites that referenced this issue Jul 12, 2019
- Fixes an issue where themes would cascade "up" the list of themes
- Provides configuration for defining custom theme options with their own sets of cascading themes

Fixes silverstripe#392
@robbieaverill
Copy link
Contributor

Fixed in subsites 2.1.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants