Does the namespace, class name and naming convention work like it does for modules?

These links don't seem to mention it:

  • I believe it should but looking at bootstrap they seem to be needing a fix git.drupalcode.org/project/bootstrap/blob/8.x-3.x/… – GiorgosK Apr 16 '19 at 4:28
  • 2
    It's not available by default, and from a logical standpoint, usually shoudln't be necessary, as the theme layer is for theming things. – Jaypan Apr 16 '19 at 4:39
  • Thanks @giorgosk ! It appears to work OOTB, using composer drupal-project install. Autoload fix be might needed though for batch and ajax callbacks though as noted in bootstrap theme. Feel free to add answer. – Joshua Graham Apr 16 '19 at 5:27
  • 2
    This depends on what you want to load, you can't use plugins or container services for example. – 4k4 Apr 16 '19 at 8:03

I believe it should but looking at bootstrap they seem to be needing a fix https://git.drupalcode.org/project/bootstrap/blob/8.x-3.x/autoload-fix.php

| improve this answer | |

There's an interesting development going on regarding themes and OOP. Look at Allow themes to provide services.yml which finally got closed as Won't Fix. From Mark Carver's closing comment:

I really don't think we should be opening up themes to services anymore.

A lot has changed (for the better) in the 5 years I've been following this issue (closely).

If this were to happen... there wouldn't be any real delineation between what a module is vs. what theme is, would there?

Instead as a result Allow themes to declare dependencies on modules is the route to go now. To move all the OOP stuff out of themes as the theme layer is for theming things, as JayPan said in the comments.

My answer to that problem is that I now always create a themename_companion module where I provide Drush 9 commands, helper functions, services etc. for my themes.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.