Problem/Motivation

Site builders often look for an easy way to create a theme, and sub-theming is a great solution, for example based on Bootstrap.

Please note that there is a distinction between a sub-theme, and a starterkit approach:

Starterkit: A clone of the original theme, totally detached from the original theme.
Sub-theme: A minimalistic approach, using a base theme for the heavy lifting, allowing overrides, with a small effort.

Proposed resolution

It would be nice if a sub-theme based on the new default Drupal front-end theme Olivero could be easily created from the command line, by adding a sub-theme folder in the Olivero theme, to use as a template for sub-theme generation.

API changes

New command for generating an Olivero sub-theme. It requires two parameters, first the machine name, then the human readable name, in quotes:

core/scripts/create-subtheme.sh "my_theme" "My Theme"

... for Composer installations, with a web folder:

web/core/scripts/create-subtheme.sh "my_theme" "My Theme"

Applying the patch

For Composer, add this in composer.json, right after the "extra": { line, like this:

"extra": {
    "composer-exit-on-patch-failure": true,
    "patchLevel": {
        "drupal/core": "-p2"
    },
    "patches": {
        "drupal/core": {
            "3214072: Provide an Olivero sub-theme creation tool": "https://www.drupal.org/files/issues/2022-02-11/olivero_subtheme-tool-3214072-82.patch"
        }
    },

Note: Remember to update the link to the patch you want to test.

Check the documentation for details on Patching projects using Composer.

Configuration (from README.md)

In order to inherit block placement of Olivero, you need to make sure the Olivero theme (the base theme) is installed and set as the site's default theme, before you install your sub theme, and set it as default.

For more, see #2635978: Sub-theme doesn't inherit base theme default block config.

The Drush commands, if your theme machinename is my_theme:

$ drush theme:enable olivero
$ drush config:set system.theme default olivero -y
$ drush theme:enable my_theme
$ drush config:set system.theme default my_theme -y

Remaining tasks

Feel free to try out the tool, and post feedback here if you encounter any errors, or if you have suggestions for improvements.

CommentFileSizeAuthor
#2 olivero_subtheme-tool-3214072-2.patch7.9 KBressa
#4 olivero_subtheme-tool-3214072-4.patch8.43 KBressa
#4 interdiff-2-4.txt1.13 KBressa
#6 olivero_subtheme-tool-3214072-6.patch9.48 KBressa
#6 interdiff-4-6.txt2.38 KBressa
#8 olivero_subtheme-tool-3214072-8.patch9.36 KBressa
#8 interdiff-6-8.txt10.59 KBressa
#9 olivero_subtheme-tool-3214072-9.patch9.36 KBressa
#9 interdiff-8-9.txt484 bytesressa
#11 olivero_subtheme-tool-3214072-11.patch8.16 KBressa
#11 interdiff-9-11.txt2.79 KBressa
#13 Sidebar region.png84.41 KBmitthukumawat
#13 Homepage screen with navigation menus.png107.27 KBmitthukumawat
#13 Footer section.png40.17 KBmitthukumawat
#13 Enable theme.png209.78 KBmitthukumawat
#13 Content screen.png53.42 KBmitthukumawat
#13 Basic site settings.png102.93 KBmitthukumawat
#13 Admin theme structure screen.png101.9 KBmitthukumawat
#20 olivero_subtheme-tool-3214072-20.patch8.48 KBressa
#20 interdiff-11-20.txt633 bytesressa
#21 olivero_subtheme-tool-3214072-21.patch8.49 KBressa
#21 interdiff-20-21.txt715 bytesressa
#29 olivero_subtheme-tool-3214072-28.patch8.62 KBressa
#29 interdiff-21-28.txt534 bytesressa
#32 Capture d’écran de 2021-07-29 20-24-30.png455.08 KBzenimagine
#39 Capture d’écran de 2021-07-29 21-43-16.png291.66 KBzenimagine
#57 Capture d’écran de 2021-07-31 21-31-04.png156.98 KBzenimagine
#58 olivero_subtheme-tool-3214072-58.patch9.89 KBressa
#58 interdiff-28-58.txt1.8 KBressa
#66 olivero_subtheme-tool-3214072-66.patch9.95 KBressa
#66 interdiff-58-66.txt929 bytesressa
#82 olivero_subtheme-tool-3214072-82.patch9.81 KBressa
#82 interdiff-66-82.txt3.99 KBressa
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ressa created an issue. See original summary.

ressa’s picture

Status: Active » Needs review
FileSize
7.9 KB

Here's the patch.

guilhermevp’s picture

Status: Needs review » Needs work
ressa’s picture

Status: Needs work » Needs review
FileSize
8.43 KB
1.13 KB

This should fix FAILURE core/themes/olivero/sub-themekit/js/scripts.js does not have a corresponding core/themes/olivero/sub-themekit/js/scripts.es6.js.

I am not sure how to deal with the Unknown word (themekit) CSpell: failed issue ...

ressa’s picture

Status: Needs review » Needs work

It's the CSS that is failing, I think. New patch coming up.

ressa’s picture

Status: Needs work » Needs review
FileSize
9.48 KB
2.38 KB

Updates the CSS, adding .pcss.css which might be required, and the CSpell: failed not the issue.

Also adds hidden: true in MACHINENAME.info.yml of the template, so it doesn't show up in the theme UI (See #2574975: Allow (base-)themes to be excluded from the UI (e.g. blocks, Appearance).).

ressa’s picture

ressa’s picture

Status: Needs work » Needs review
FileSize
9.36 KB
10.59 KB

Renamed sub-themekit folder to subtheme to pass the CSpell check, based on @quietone's excellent answer in #3214108: False CSpell positive by core/scripts/dev/commit-code-check.sh.

ressa’s picture

FileSize
9.36 KB
484 bytes

Trying with a fresh CSS file, perhaps that's the issue.

Status: Needs review » Needs work

The last submitted patch, 9: olivero_subtheme-tool-3214072-9.patch, failed testing. View results

ressa’s picture

FileSize
8.16 KB
2.79 KB

That was better, but still fails ... trying with a simpler CSS and js file structure, since simplicity in a sub-theme is the goal.

ressa’s picture

Status: Needs work » Needs review
mitthukumawat’s picture

I did manually testing of the patch #11. It applied cleanly for me.
The Olivero sub theme is appearing as expected for me.

Testing steps:

  • Created an olivero_subtheme folder under themes/custom in Drupal 9.3.x-dev version.
  • Created olivero_subtheme.info.yml and olivero_subtheme.libraries.yml files in olivero_subtheme folder and write proper dependencies in these files.
  • Created css and js folders and empty css and js files respectively.
  • Enabled the olivero_subtheme in appearance section and enabled it as admin theme as well.
  • The theme appearance is looking exactly like base Olivero theme.

Adding few screenshots of olivero subtheme.

ressa’s picture

Thanks for the thorough testing and images @mitthukumawat. It does look like the logo image is missing in the Homepage screen with navigation menus.png image ...

Perhaps you can check if the logo.svg image is present in the theme folder at all, or if it is a permission issue?

mitthukumawat’s picture

Yeah, it was the logo image not present in subtheme folder. But it is in base theme (Olivero) folder. So I think it should get the logo from base theme.
As after placing the logo image in subtheme folder, it is appearing now.

ressa’s picture

Status: Needs review » Postponed (maintainer needs more info)

The logo image is included in the subtheme folder, inside the Olivero folder, so it should just get copied ...

Can I ask you to run these commands and paste the result here?

$ core/scripts/create-subtheme.sh my_theme
That theme name looks good, continuing ...
Theme 'My theme' created successfully in themes/my_theme ...

$ ls -algG core/themes/olivero/subtheme/
total 40
drwxrwxr-x  5 4096 May 18 13:21 .
drwxrwxr-x 10 4096 May 18 13:21 ..
drwxrwxr-x  2 4096 May 18 13:21 css
drwxrwxr-x  2 4096 May 18 13:21 js
-rw-r--r--  1 1069 May 18 13:21 logo.svg
-rw-r--r--  1  610 May 18 13:21 MACHINENAME.info.yml
-rw-r--r--  1  158 May 18 13:21 MACHINENAME.libraries.yml
-rw-r--r--  1   93 May 18 13:21 MACHINENAME.theme
-rw-r--r--  1  794 May 18 13:21 README.md
drwxrwxr-x  2 4096 May 18 13:21 templates

$ ls -algG themes/my_theme
total 40
drwxrwxr-x 5 4096 May 19 11:32 .
drwxrwxr-x 4 4096 May 19 11:32 ..
drwxrwxr-x 2 4096 May 19 11:32 css
drwxrwxr-x 2 4096 May 19 11:32 js
-rw-r--r-- 1 1069 May 19 11:32 logo.svg
-rw-r--r-- 1  590 May 19 11:32 my_theme.info.yml
-rw-r--r-- 1  158 May 19 11:32 my_theme.libraries.yml
-rw-r--r-- 1   93 May 19 11:32 my_theme.theme
-rw-r--r-- 1  794 May 19 11:32 README.md
drwxrwxr-x 2 4096 May 19 11:32 templates
ressa’s picture

Status: Postponed (maintainer needs more info) » Needs review
Issue tags: +Site builder experience (SX)

I just re-read your comment, and only now realize you didn't use the command line tool, which probably explains the missing image.

If you want to test without using the command line tool, it is much safer to copy the subtheme folder from the Olivero theme to the global themes folder, which would guarantee that all important files and folders are included.

After that you should rename all relevant folders, files, and names, check the create-subtheme.sh script for details. I hope that helps?

mitthukumawat’s picture

@ressa
You are right. I did not used command line instead I did the subtheme setup manually. After following command line, I can see the files safely copied in subtheme. Thanks for the #16.

ressa’s picture

Thanks for confirming that it works as designed, @mitthukumawat.

ressa’s picture

Adding a simple check on number of files in origin (subtheme folder) and destination, which is the created sub-theme, to see if it was created as planned.

ressa’s picture

Fixing a few "CSpell: failed" issues.

ressa’s picture

Issue summary: View changes

Adds Configuration in Issue Summary.

ressa’s picture

ressa’s picture

Status: Needs review » Closed (duplicate)
Parent issue: » #3190946: [META] Subtheming Olivero

Closing this issue, since another solution already exists.

ressa’s picture

Component: theme system » Olivero theme

Updating Component.

ressa’s picture

Status: Closed (duplicate) » Active
Issue tags: +subtheme

Actually, https://github.com/mherchel/olivero-subtheme seems to use a starterkit approach (see #3050384: Provide a starterkit theme in core) or in other words: A cloned and modified Olivero theme, detached from Olivero.

This solution is a more minimal sub-theme approach, allowing a site builder to make small tweaks with minimal effort, not requiring Node and Yarn, or to know how *.es6.js works, so reopening the issue, since it is not a duplicate.

ressa’s picture

Related issues: +#2554199: Bootstrap 4
ressa’s picture

Issue summary: View changes
ressa’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
8.62 KB
534 bytes

Adds support for running the command from root-folder in both Git-based (all files in root) and Composer-based (scaffolded) installations:

  • Git: core/scripts/create-subtheme.sh my_theme
  • Composer: web/core/scripts/create-subtheme.sh my_theme
ressa’s picture

Adding Remaining tasks section in the Issue Summary, encouraging feedback.

zenimagine’s picture

I have a site in production with Olivero to activate (Drupal 9.2.2). I need to modify some css. Should I use https://github.com/mherchel/olivero-subtheme or this patch ? Thank you

zenimagine’s picture

@ressa I just tested the patch, but I failed to create the subtheme

ressa’s picture

I don't see the core/scripts/create-subtheme.sh file ... I will update the Issue Summary with an example of how to apply the patch, since it's not obvious.

ressa’s picture

Issue summary: View changes

Adding patch example.

ressa’s picture

@zenimagine: This issue is aimed at creating a sub-theme tool in Drupal core for Olivero. My impression is that https://github.com/mherchel/olivero-subtheme is more a starterkit, essentially cloning Olivero, so by definition not a sub-theme ...

ressa’s picture

Issue summary: View changes
ressa’s picture

Issue summary: View changes

Adds Drush commands in Issue Summary for enabling Olivero, setting it as default, and the same for the new sub-theme.

zenimagine’s picture

i dont understand because i added the patch to composer.json

zenimagine’s picture

@rassa I had applied the patch as I usually do, but there is no script in the folder

ressa’s picture

Sorry, but I haven't tried that way ... perhaps you could try patching manually?

https://www.drupal.org/project/drupal/issues/3214072#summary-patching

zenimagine’s picture

@ressa I will test tomorrow because it is late, but a patch is applied normally in the composer.json

This is a good practice explained in the drupal documentation.

ressa’s picture

Sounds good @zenimagine, I need all the help I can get, so please share it here if you figure out why Composer workflow doesn't work ... I tried with this in composer.json. The patch seems to get applied, but the files are not created:

        "enable-patching": "true",
        "composer-exit-on-patch-failure": true,
        "patches": {
            "drupal/core": {
                "Olivero subtheme": "https://www.drupal.org/files/issues/2021-06-14/olivero_subtheme-tool-3214072-28.patch"
            }
        },

Running Composer:

$ composer update -vvv
[...]
> post-package-install: Drupal\Composer\Plugin\Scaffold\Plugin->postPackage
> post-package-install: cweagans\Composer\Patches->postInstall
  - Applying patches for drupal/core
    https://www.drupal.org/files/issues/2021-06-14/olivero_subtheme-tool-3214072-28.patch (Olivero subtheme)
Downloading https://www.drupal.org/files/issues/2021-06-14/olivero_subtheme-tool-3214072-28.patch
patch '-p1' --no-backup-if-mismatch -d 'web/core' < '/tmp/610316910a71c.patch'
Executing command (CWD): patch '-p1' --no-backup-if-mismatch -d 'web/core' < '/tmp/610316910a71c.patch'
patching file core/scripts/create-subtheme.sh
patching file core/themes/olivero/subtheme/MACHINENAME.info.yml
patching file core/themes/olivero/subtheme/MACHINENAME.libraries.yml
patching file core/themes/olivero/subtheme/MACHINENAME.theme
patching file core/themes/olivero/subtheme/README.md
patching file core/themes/olivero/subtheme/css/style.css.template
patching file core/themes/olivero/subtheme/js/scripts.js.template
patching file core/themes/olivero/subtheme/logo.svg
patching file core/themes/olivero/subtheme/templates/README.md

To force Composer to apply the patch during testing, found in Composer-Patches: The Dependency You Never Knew You Needed:
$ rm -rf web/core && rm -rf vendor

james.williams’s picture

On projects following the recommended webroot structure for core, applying core patches with cweagans/composer-patches needs to happen using the 'p2' patch level (i.e. to reach inside the webroot directory when the project composer.json is a level above that). Patches that simply add files can technically apply at any level, but that can mean the files get created in the wrong place. To ensure they get applied in the right place, add this to your composer.json, in the 'extra' section, i.e. next to the 'patches' section:

...
    "composer-exit-on-patch-failure": true,
    "patchLevel": {
      "drupal/core": "-p2",
      "drupal/contrib-module1": "-p1",
      "drupal/contrib-module2": "-p1",
    }
    "patches": {
...

It's worth listing any contrib modules that you are patching, to explicitly use 'p1', to help verify that patches are applied correctly.

ressa’s picture

Issue summary: View changes

Thanks a lot for helping out @james.williams, that was the missing piece in the puzzle :-)

This works well, and Drupal core gets patched as expected:

"composer-exit-on-patch-failure": true,
"patchLevel": {
    "drupal/core": "-p2"
},
"patches": {
    "drupal/core": {
        "3214072: Provide an Olivero sub-theme creation tool": "https://www.drupal.org/files/issues/2021-06-14/olivero_subtheme-tool-3214072-28.patch"
    }
},

I have added your detailed explanation to a new "Patching Drupal core" section on the Using Composer to Install Drupal and Manage Dependencies documentation page, I hope it's all right.

james.williams’s picture

You're very welcome - I'm glad to help! Thanks for adding that to that documentation. What needs to happen to progress this? Any particular kind of reviews of anything in particular, from anyone in particular?

ressa’s picture

Great! The Drupal core patch info on the documentation page can hopefully prevent someone else from wasting too much time with that.

I am not sure what the procedure is ... feedback here after trying the tool would certainly be useful: If it worked, suggestions for improvement, etc. Now that we got the patching part fixed thanks to your excellent advice, it should be easier for others to try out.

Do you have any feedback, for example about the script, or if any files could be added or removed from the template structure?

james.williams’s picture

I haven't had time to actually have a go myself; the project that I'm interested in this for isn't a paying client so I can only give it so much of my time. Sorry! For me, #3086514: Investigate use of the changing color themes for Olivero is what I'm really after; this sub-theming tool would be a useful alternative if that doesn't progress.

zenimagine’s picture

Thanks, I confirm that the file is now created. However I have this message which prevents using the script. It's probably not a Drupal problem, but what if you have any idea ? I am in a shared hosting, I do not have access to sudo

uid170869@od-8ca868:~/sites/www.example.fr$ core/scripts/create-subtheme.sh subtheme_olivero
bash: core/scripts/create-subtheme.sh: Permission denied
james.williams’s picture

@zenimagine If you don't have control over your file permissions / access in your shared hosting, it's best to run the script on a local development copy of your site. Then you can review the changes and upload / push them to your shared hosting. Scripts like this (including composer!) aren't usually recommended to be ran in production environments or on remote hosting that you can't control.

zenimagine’s picture

ok thanks, i succeeded. The sub-theme is in the themes/my_theme folder, shouldn't it be in themes/custom/my_theme ?

ressa’s picture

From what I can tell, #3050384: Provide a starterkit theme in core also places a generated theme in the /themes folder. But feel free to update the script and upload a patch.

zenimagine’s picture

ok this is different from Drupal 8. One last question, I want to change the color blue all over the website. How to do this ? I want to replace #2494db by #1f71b8

ressa’s picture

It's really just a matter of choice ... you are free to place your custom theme in /themes/custom.

You can change the "Header site branding background color" by copying the function from core/themes/olivero/theme-settings.php into themes/my_theme/my_theme.theme, updating the function name to my_theme_form_system_theme_settings_alter and adding 'darkblue' => t('Dark Blue'),:

/**
 * @file
 * Functions to support Olivero theme settings.
 */

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_FORM_ID_alter() for system_theme_settings.
 */
function my_theme_form_system_theme_settings_alter(&$form, FormStateInterface $form_state) {
  $form['olivero_settings']['olivero_utilities'] = [
    '#type' => 'fieldset',
    '#title' => t('Olivero Utilities'),
  ];
  $form['olivero_settings']['olivero_utilities']['mobile_menu_all_widths'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable mobile menu at all widths'),
    '#default_value' => theme_get_setting('mobile_menu_all_widths'),
    '#description' => t('Enables the mobile menu toggle at all widths.'),
  ];
  $form['olivero_settings']['olivero_utilities']['site_branding_bg_color'] = [
    '#type' => 'select',
    '#title' => t('Header site branding background color'),
    '#options' => [
      'default' => t('Primary Branding Color'),
      'gray' => t('Gray'),
      'white' => t('White'),
      'darkblue' => t('Dark Blue'),
    ],
    '#default_value' => theme_get_setting('site_branding_bg_color'),
  ];
}

Add this in themes/my_theme/css/style.css:

.site-branding--bg-darkblue {
  background: #1f71b8;
}

Clear cache, and switch to "Dark Blue" under "Olivero Utilities" > "Header site branding background color" on admin/appearance/settings/my_theme.

To be able to change more colors see #3086514: Investigate use of the changing color themes for Olivero. As @KarinG writes in comment #22:

We colour Olivero into an organization's primary colour - always. It's do-able with a lot of css overrides (packaged into a subtheme). It would be great to have a configuration option for it. Happy to help test any solutions.

zenimagine’s picture

Thank you, but it's complicated to apply a change everywhere on the site, brand, link, button, ...

I wait for a next update with this functionality, as simple as Bootstrap.

zenimagine’s picture

Is it normal that the responsive images do not work with Olivéro and the sub themes ?

/admin/config/media/responsive-image-style

ressa’s picture

Do you mean that it works in Olivero, but not a Olivero sub-theme?

zenimagine’s picture

The sub-theme does not appear in responsive styles and responsive images does not even work with the base theme.

ressa’s picture

Thanks for clarifying @zenimagine. It looks like a sub-theme needs its own Breakpoint file (themename.breakpoints.yml). Does this new patch fix it?

I don't know if responsive images works or not in Olivero ...

ressa’s picture

Issue summary: View changes

Removes the Git patch example from the Issue Summary.

zenimagine’s picture

@ressa Thanks for the patch, it works. But the adaptive images are not consistent with the configuration.

ressa’s picture

Sounds good @zenimagine, thanks for confirming that it is a step in the right direction. Perhaps you can list the steps required to make it work in Olivero, and show the expected behavior, and how it fails in an Olivero sub-theme?

zenimagine’s picture

@ressa I just sent you a private message to show you the problem on a clean install.

ressa’s picture

It looks like the adaptive image problem is a general Olivero problem, for more see #3222784: Olivero: 'wide-content' utility class breaks layout when placed in 'Hero' region.

The patch from #58 still applies and works fine with the latest dev-release of Drupal 9.3. Just to make sure, I triggered a re-test which passed.

I still think this would be a valuable tool, and the easiest way to get a theme with excellent support and future-proofing, which Olivero will have, since it is the next Drupal front-end theme. So any feedback is still appreciated, even if it is just "it works!" :-)

aangel’s picture

Fabulous. Wish I had seen this earlier.

For others, the build script that copies the core Olivero into a new, custom theme (not a subtheme) described here fails. Some of the differences are outlined in this issue.

The workaround to that is to perform the alternative manual steps. But this is certainly the preferred way, from my point of view.

I'll try this now.

aangel’s picture

I added the patch from #58 to composer on a 9.2.8 project and it applied successfully. Then, from the project root here's what I saw:

% web/core/scripts/create-subtheme.sh aarc
zsh: permission denied: web/core/scripts/create-subtheme.sh
% chmod +x web/core/scripts/create-subtheme.sh
% web/core/scripts/create-subtheme.sh aarc    
That theme name looks good, continuing ...

web/core/scripts/create-subtheme.sh: line 73: ${themename^}: bad substitution
sed: 1: "themes/aarc/MACHINENAME ...": undefined label 'hemes/aarc/MACHINENAME.info.yml'
sed: 1: "themes/aarc/MACHINENAME ...": undefined label 'hemes/aarc/MACHINENAME.breakpoints.yml'
sed: 1: "themes/aarc/MACHINENAME ...": undefined label 'hemes/aarc/MACHINENAME.info.yml'
Theme 'aarc' created successfully in themes/aarc ...

Then I ran the instructions for enabling the theme and pulled up the home page. It gave me the error ".../templates/html.twig.php" file is missing. Sure enough, the entire templates directory is empty except for a README.md.

ressa’s picture

Thanks for testing the patch @aangel. It looks like a known issue with sed in macOS or zsh: sed command hits “undefined label” error on Mac OS X.

I have updated the patch, and added .bak files with the sed commands, perhaps that fixes it for you?

ifrik’s picture

Using Drupal 9.2.8: I've applied the patch #66 using composer, but the create-subtheme.sh script is created in a new subdirectory of core:
web/core/core/scripts

But it turns out I had not changed the patchLevel as described in the issue summary above.

ressa’s picture

Great that you got it working @ifrik, patching Drupal core with Composer can be tricky. For the same reason, I recently updated the documentation on how to patch Drupal core and modules using Composer. Feel free to review it and clarify or expand any part of it.

Can you confirm whether or not theme was created correctly for you?

ressa’s picture

Version: 9.3.x-dev » 9.4.x-dev

Updating to latest version.

fotidim’s picture

In my case the patch was not being applied at all using Composer and I needed to do "composer require cweagans/composer-patches".

Maybe it's worth adding that to the documentation.
I just saw that it is already there.

ressa’s picture

Issue summary: View changes

Thanks for the feedback @fotidim, I have added a link under the Applying the patch section.

Did you get the sub-theme working?

andypost’s picture

+++ b/core/scripts/create-subtheme.sh
@@ -0,0 +1,106 @@
+if [ -d web/core/themes/olivero ]

not sure new bash script is good idea when there's core's tool https://www.drupal.org/node/3206389

andypost’s picture

fotidim’s picture

@ressa I did! What is the recommended way to customize CSS? I read the instructions here but there is no "package.json" neither in my subtheme or Olivero itself. I can only find a package.json if I clone the theme from its repo.

altrugon’s picture

I have applied patch from comment #66 and ended up with the same "bad substitution" result from comment #65. Here is the output from my console:

$ chmod +x web/core/scripts/create-subtheme.sh
$ web/core/scripts/create-subtheme.sh newtheme2022
That theme name looks good, continuing ...
web/core/scripts/create-subtheme.sh: line 73: ${themename^}: bad substitution
Theme 'olivero2022' created successfully in themes/olivero2022 ...

As far as I can see everything works fine, but I'm missing the *.pcss files, the scripts to run the code compilation, and maybe some instruction in the README.md file about how this process should be done. Creating a sub-theme and not being able to adjust the values of the variables doesn't seem right to me, am I missing an step here?

Thank you so much to everybody for the hard work.

altrugon’s picture

I kept working on the theme until I was able to compile the *.pcss.css files. As I mentioned before a sub-theme loose its value if you are not able to change the values of its parent variable. For clarification I'm going to refer to the parent theme as "olivero" and the sub-theme as "subtheme". Here are all the changes I had to do in order to be able to compile the source code:

1. Set node version and yarn version

According to Drupal'spackage.json we need to use Node v12 and Classic Yarn.

  ...
  "engines": {
    "yarn": ">= 1.6",
    "node": ">= 12.0"
  },
  ...

The easiest way I found to get this set was via Node Version Manager, go to subtheme's root folder and run the following commands:

$ nvm use v12 > .nvmrc
$ yarn set version classic
$ node --version && yarn --version
v12.22.10
1.23.0-20220130.1630

2. Bringing files into the subtheme

You are going to need a few files in order to be able to compile the source code, follow these steps:

  1. Replace subtheme/css folder with olivero/css folder.
  2. Copy olivero/layout/html.html.twig file into subtheme/layout/ and delete line #43 {% include '@olivero/includes/preload.twig' with { olivero_path: olivero_path } only %}. This line load a bunch of font files that you may not want to use.
  3. Copy /core/package.json file into subtheme/ and delete from line #11 & yarn build:ckeditor5, and from line #12 & yarn watch:ckeditor5.
  4. Copy /core/scripts into subtheme/. You don't need all the scripts but I haven't gone through the clean up process yet at this point.

3. Load the right libraries

Now you need to make sure you load the libraries from subtheme and not olivero's libraries, in order to do that subtheme.info.yml and subtheme.libraries.yml have to look as follow:

subtheme.info.yml

  name: 'subtheme'
  type: theme
  base theme: olivero
  description: 'An Olivero based sub-theme.'
  package: 'Olivero'
  version: 1.x
  core_version_requirement: ^8 || ^9 || ^10
  regions:
    header: Header
    primary_menu: 'Primary menu'
    secondary_menu: 'Secondary menu'
    hero: 'Hero (full width)'
    highlighted: Highlighted
    breadcrumb: Breadcrumb
    social: Social Bar
    content_above: Content Above
    content: Content
    sidebar: 'Sidebar'
    content_below: 'Content Below'
    footer_top: 'Footer Top'
    footer_bottom: 'Footer Bottom'
  libraries:
    # - subtheme/global-styling
    - subtheme/global-scripts
  # Override the system.theme.css file with our version in the ./css subdirectory:
  # https://www.drupal.org/docs/theming-drupal/adding-stylesheets-css-and-javascript-js-to-a-drupal-theme#override-extend
  libraries-override:
    olivero/global-styling: subtheme/global-styling
    olivero/feed: subtheme/feed
    olivero/navigation-secondary: subtheme/navigation-secondary
    olivero/progress: subtheme/progress
    system/base:
      css:
        component:
          /core/themes/olivero/css/components/ajax-progress.module.css: css/components/ajax-progress.module.css
          /core/themes/olivero/css/components/autocomplete-loading.module.css: css/components/autocomplete-loading.module.css
    subtheme/global-styling:
      js:
        js/checkbox.js: /core/themes/olivero/js/checkbox.js
        js/navigation-utils.js: /core/themes/olivero/js/navigation-utils.js  

subtheme.libraries.yml

  global-styling:
  version: VERSION
  css:
    base:
      css/base/fonts.css: {}
      css/base/variables.css: {}
      css/base/base.css: {}
      css/base/utility.css: {}
    layout:
      css/layout/layout.css: {}
      css/layout/grid.css: {}
      css/layout/layout-content-narrow.css: {}
      css/layout/layout-content-medium.css: {}
      css/layout/layout-footer.css: {}
      css/layout/region.css: {}
      css/layout/region-content.css: {}
      css/layout/region-hero.css: {}
      css/layout/region-secondary-menu.css: {}
      css/layout/social-bar.css: {}
      css/layout/views.css: {}
    component:
      css/components/block.css: {}
      css/components/breadcrumb.css: {}
      css/components/embedded-media.css: {}
      css/components/footer.css: {}
      css/components/button.css: {}
      css/components/container-inline.module.css: {}
      css/components/fieldset.css: {}
      css/components/field.css: {}
      css/components/form.css: {}
      css/components/form-boolean.css: {}
      css/components/form-text.css: {}
      css/components/form-textarea.css: {}
      css/components/form-select.css: {}
      css/components/header-buttons-mobile.css: {}
      css/components/header-navigation.css: {}
      css/components/header-site-branding.css: {}
      css/components/header-sticky-toggle.css: {}
      css/components/hero.css: {}
      css/components/links.css: {}
      css/components/messages.css: {}
      css/components/navigation/nav-button-mobile.css: {}
      css/components/node.css: {}
      css/components/node-teaser.css: {}
      css/components/page-title.css: {}
      css/components/site-header.css: {}
      css/components/skip-link.css: {}
      css/components/pager.css: {}
      css/components/table.css: {}
      css/components/text-content.css: {}
      css/components/tabledrag.css: {}
      css/components/wide-image.css: {}

  js:
    js/checkbox.js: {}
    js/navigation-utils.js: {}

  dependencies:
    - core/drupal.element.closest
    - core/drupal.element.matches
    - core/drupal.nodelist.foreach
    - core/drupal
    - core/once
    - core/tabbable

feed:
  version: VERSION
  css:
    theme:
      css/components/feed.css: {}

navigation-secondary:
  version: VERSION
  css:
    component:
      css/components/navigation/nav-secondary.css: {}

progress:
  version: VERSION
  css:
    component:
      css/components/progress.css: {}

global-scripts:
  js:
    js/scripts.js: {}
  dependencies:
    - core/drupal
    - core/jquery

4. Time to compile

You should be set up, go to subtheme's root folder and run the following command:

yarn watch

If I didn't missed anything you should now be able to see something like this in your command line:

  yarn run v1.23.0-20220130.1630
  $ yarn watch:css & yarn watch:js
  $ node ./scripts/css/postcss-watch.js
  $ cross-env BABEL_ENV=legacy node ./scripts/js/babel-es6-watch.js
  [03:32:20] Watching './**/*.es6.js' for changes.
  [03:32:21] Watching './**/*.pcss.css' for changes.  

I hope this help others, feedback are welcome, and it would be nice to have all these task integrated in the script.

ressa’s picture

Thanks for sharing that @andypost. Since the operations are mostly moving and renaming files, I would think Bash is a better tool for the job than PHP? Of course, if Bash is not acceptable, the tool should be re-written in PHP.

ressa’s picture

@fotidim: Just edit the css/style.css file :)

About https://github.com/mherchel/olivero-subtheme - That is a starterkit, and not a sub-theme. Please read my comment above in #26 for details.

ressa’s picture

@altrugon: Great that you got it working!

But in my mind, this subtheme tool should be as lean as possible, aimed at site builders to give them an easy way to create a subtheme in seconds, simply by running a single command. After that, they can override the base theme by editing the css/style.css file.

To get all the bells and whistles, I think a starterkit approach is the right way, see #3206219: Allow configuring which theme is used as a starterkit theme.

About the bad substitution error, are you using an older Bash version, or perhaps Z shell (Zsh)?

You can convert the case of the string more easily by using the new feature of Bash 4. ‘^’ symbol is used to convert the first character of any string to uppercase

https://linuxhint.com/bash_lowercase_uppercase_strings/

I did some testing, and perhaps you can experiment with different options, if we need to create a special solution for Zsh? It would be great though, if it worked for both Bash and Zsh ...

$ themename=newtheme2022
$ echo ${themename^}
Newtheme2022
ressa’s picture

I just tried #3206219: Allow configuring which theme is used as a starterkit theme with Drupal 10.0.x-dev and I could create a detached new theme (i.e. not a subtheme) based on Bartik after adding starterkit: true in bartik.info.yml with this:

$ php core/scripts/drupal generate-theme --name "bartik_new" --starterkit bartik bartik_new
Theme generated successfully to themes/bartik_new

This approach doesn't yet work for Olivero, but hopefully will at some point, see comments #11-#15 in #3206219: Allow configuring which theme is used as a starterkit theme for the discussion, as well as #3206217: Allow starterkit themes to control how the theme is generated where it looks like Olivero support might be added, which would be awesome.

ressa’s picture

Issue summary: View changes
ressa’s picture

Here's a new patch which adds a second parameter, to define the human readable name, which also avoids the command which gave the bad substitution error in Zsh.

ressa’s picture

Issue summary: View changes

Makes Applying the patch section a little clearer.

mglaman’s picture

This should leverage the key added in #3206219: Allow configuring which theme is used as a starterkit theme and postponed on #3206217: Allow starterkit themes to control how the theme is generated. Once we have the latter, everything just needs to exist in the StarterKit class.

mglaman’s picture

Status: Needs review » Needs work

#3206217: Allow starterkit themes to control how the theme is generated has landed. Let's create a Drupal\olivero\StarterKit class and make this possible!

ressa’s picture

That's nice! But since the aim of this issue is to create a sub-theme tool, and not fork ("Starterkit") does it still make sense? From the Issue Summary:

Please note that there is a distinction between a sub-theme, and a starterkit approach:

Starterkit: A clone of the original theme, totally detached from the original theme.
Sub-theme: A minimalistic approach, using a base theme for the heavy lifting, allowing overrides, with a small effort.

mglaman’s picture

I see. It seems like Drupal core is moving against promoting sub-themes from Drupal core due to backward compatibility requirements. I'm for opening a different ticket for starter kit and letting this one be. I just don't think a script for subtheming will make it.

ressa’s picture

I agree, a new issue is probably the right way forward. But I am all for having a starterkit option--the more choices, the better!

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mherchel’s picture

Status: Needs work » Closed (won't fix)

Closing this in favor of #3302625: Allow Olivero to be cloned by Starterkit theme generator, so we can focus on the ability to clone Olivero.

ressa’s picture

Adding issues about phasing out Bash scripts, so a sub-theme tool should probably be written in PHP, as @andypost also wrote in comment #72.