Problem/Motivation

Create a subtheme from bootstrap5 theme, which Drupal doesn't list under /admin/appearance

Steps to reproduce

Create a subtheme from bootstrap5: /admin/appearance/settings/bootstrap5/. The subtheme folder exists. But drupal doesn't list it in: /admin/appearance/

Proposed resolution

Add checks in the code so that all the rules on Naming and placing your Drupal module are followed.

The method used in the code (regex, strlen, or in_array) is shown after each rule, and the existing check is stroked-through:

  • It must start with a letter. (regex)
  • It must contain only lower-case letters, digits, and underscores. (regex)
  • It must not contain any spaces. (regex)
  • It must not be longer than 50 characters. (strlen)
  • It must be unique. Your module should not have the same short name as any other module, theme, theme engine, or installation profile you will be using on the site. (in_array DONE)
  • It should not be any of the reserved terms : src, lib, vendor, assets, css, files, images, js, misc, templates, includes, fixtures, Drupal.(in_array)

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#10 3329010-1.patch1.48 KBschiz0id

Issue fork bootstrap5-3329010

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

FvD created an issue. See original summary.

fvd’s picture

Title: Do't see created subtheme » Don't see created subtheme
abyss’s picture

Hi @FvD, have you started fixing this or can I start fixing this issue?

abyss’s picture

Assigned: Unassigned » abyss
fvd’s picture

Hi @Abyss, do you start to fix it. (Im very new to drupal) thanks

abyss’s picture

Assigned: abyss » Unassigned
Status: Active » Needs review

I added a function for replacing a space on the underline for the subtheme machine name field. Now, if the user enters an incorrect machine name for the subtheme, it will be corrected during its generation.

schiz0id’s picture

@Abyss thanks for looking into this.

Your commit does fix the underscore issue. I tested it, and it works fine.

However, I tried testing it out a couple different ways to try and break it. The machine name for a theme should only consist of lowercase letters, underscores, and numbers. They should also start with a letter. Even with your fix in place, I'm still able to create a theme with a machine name that begins with a number (8theme_test, for example).

The reason this is problematic is because the subtheme has to use theme hooks, which are PHP functions, and the function names have to start with the machine name. If you allow a machine name to begin with a number, PHP is going to throw syntax errors because this function/theme hook would be invalid:

function 8theme_test_css_alter()

---

Edit: I got bored and decided to write a regex form validation for this. Attaching a patch.

schiz0id’s picture

Status: Needs review » Needs work
schiz0id’s picture

StatusFileSize
new1.48 KB
schiz0id’s picture

Status: Needs work » Needs review

ressa made their first commit to this issue’s fork.

ressa’s picture

Issue summary: View changes

Thanks @schiz0id, I agree that using regex is a more robust solution. Based on your patch, I have updated the 3329010-dont-see-created fork.

I added the regex check as a separate function and simplified the regex a little bit, I think this should also work.

I also added a check for machine name length is 50 characters, and for the reserved terms listed on Naming and placing your Drupal module.

ressa’s picture

Title: Don't see created subtheme » Check that new subtheme comply with all machine name rules
fvd’s picture

Thank you, @ressa, @schiz0id, @Abyss.

It works for me

ressa’s picture

Thanks for testing the patch @FvD, and also for posting the bug in the first place, since it showed that the missing checks allowed malformed sub-theme machine names, in many different ways.

Feel free to change the Status to Reviewed & tested by the community if you think the code can move on, and get committed.

schiz0id’s picture

Thanks, @ressa! I didn't know I could get access to the forked repo or I would have made a commit. I'll keep that in mind next time.

I went ahead and pulled down your changes and manually ran through all of the validations we put together, and they work! Thanks again for pushing this across the finish line.

schiz0id’s picture

Status: Needs review » Reviewed & tested by the community
ressa’s picture

You're welcome @schiz0id! There are so many things to keep in mind with the (not so) new Gitlab system. I kept forgetting that I need to click "Get push access" to and existing forks, and then log in at Gitlab, and THEN I can push to existing branches. After much repetition, I think I finally got the steps down.

Thanks for reviewing the code, this will be a nice improvement to the Boostrap5 sub-theme tool. Have a nice day!

VladimirAus made their first commit to this issue’s fork.

  • VladimirAus committed 43693dab on 3.0.x authored by Abyss
    Issue #3329010 by ressa, Abyss, schiz0id, FvD, VladimirAus: Check that...

  • VladimirAus committed 5ca41110 on 2.0.x authored by schiz0id
    Issue #3329010 by ressa, Abyss, schiz0id, FvD, VladimirAus: Check that...

  • VladimirAus committed e1cf6378 on 3.0.x authored by schiz0id
    Issue #3329010 by ressa, Abyss, schiz0id, FvD, VladimirAus: Check that...
vladimiraus’s picture

Status: Reviewed & tested by the community » Fixed

Thank you. 🙏
Committed to both 2 and 3 and addresses t() function.

ressa’s picture

Perfect, thanks @VladimirAus!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.