Problem/Motivation
In code there is support for themes without a theme engine. I.e where the engine is defined like
engine: false
or
engine: ''
in the theme's .info.yml.
This support is done in \Drupal\Core\Theme\ThemeInitialization::loadActiveTheme()
public function loadActiveTheme(ActiveTheme $active_theme) {
// Initialize the theme.
if ($theme_engine = $active_theme->getEngine()) {
// Include the engine.
include_once $this->root . '/' . $active_theme->getOwner();
if (function_exists($theme_engine . '_init')) {
foreach ($active_theme->getBaseThemes() as $base) {
call_user_func($theme_engine . '_init', $base->getExtension());
}
call_user_func($theme_engine . '_init', $active_theme->getExtension());
}
}
else {
// include non-engine theme files
foreach ($active_theme->getBaseThemes() as $base) {
// Include the theme file or the engine.
if ($base->getOwner()) {
include_once $this->root . '/' . $base->getOwner();
}
}
// and our theme gets one too.
if ($active_theme->getOwner()) {
include_once $this->root . '/' . $active_theme->getOwner();
}
}
// Always include Twig as the default theme engine.
include_once $this->root . '/core/themes/engines/twig/twig.engine';
}
It is completely untested and if you omit the engine key in theme.info.yml file we merge in the default of 'twig' in \Drupal\Core\Extension\ThemeExtensionList
Proposed resolution
Remove the supposed support of such themes.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
alexpottI've created a theme with an info file like so:
I also did
engine: falseThe result in the UI was this:
However via drush...
hmmm...
Comment #3
alexpottSo even if you use Drush to install such a theme and then use drush to set it as the default theme... then there is no engine but there also cannot be an owner because owner is set liek this:
And without an owner nothing is going to happen here:
So for me this is truly dead code.
Comment #4
alexpottIn system controller we do
We just don't support a theme without an engine and thereby an owner.
We could add
to
\Drupal\Core\Extension\ThemeExtensionList::createExtensionInfo()to catch the case where someone has hacked a theme with no engine to be installed. But doing that will prevent the "This theme requires the theme engine to operate correctly" message in the UI. So I'm not really a fan of that... so what I've done is to add this only if the theme is installed.Comment #6
alexpottNice - of course we do have a place where we have a theme without an engine! kernel tests with no theme... so that falls back to
We can set up the engine here.
Comment #7
alexpottDiscussed with @catch in slack. We agreed that having a CR here is noise as it is very unlikely someone is running a site with a theme without a theme engine. We also agreed to trigger a real warning in ThemeExtensionList to tell sites that they are in this state. For theme the fix is to make
engine: twigin their template.Comment #9
lauriiiI'm not sure why we are assuming that this is potential support? Because of the lack of test coverage? I cannot figure out any reason for using this so I don't believe it would be common to use this feature. However, it has been added intentionally on this issue: #137211: Move discovery of theme information to .info files (and improve theme inheritance). Therefore I agree on deprecating it since there could be themes using this feature.
Comment #10
alexpottNow with an engine the core theme messes up the registry so we need to special case that.
Comment #12
alexpottLooks like I went one step too far...
Comment #13
alexpottFinal fix I think. Something very very interesting going on in low level layout stuff in Kernel tests.
Comment #14
alexpottOh weird... HEAD \Drupal\Tests\layout_discovery\Kernel\LayoutTest does not pass for me. So the patch in #12 will be green. Re-uploading that one.
Comment #16
alexpottOpened #3020388: \Drupal\Tests\layout_discovery\Kernel\LayoutTest passes on DrupalCI but not locally for the weirdness in #13/#14
Comment #17
borisson_Since we're not adding a CR, are we linking to this issue in the trigger_error?
Comment #18
alexpott@borisson_ I discussed this with @catch and we agreed to trigger a non silenced
E_USER_WARNINGhere. Just haven't updated the patch yet.Comment #27
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.