Current Situation

Most declarations on Drupal 8 were moved to YAML files, which not the case for the theme declarations.
So themes are still declared with hook_theme() implementation.
Also there is no much information regarding themes for Admin UI purposes: label, description, category, etc.

The request

Allow themes to be declared on YAML file *.themes.yml.
This declaration should provide classes, which will allow to extend the API.
Classes declare methods to declare the themes and get implementations.
Contributed module Styles API does the job for now.

Comments

hatuhay created an issue. See original summary.

dawehner’s picture

That sounds really interesting, given that hook_theme() is one of the few left over registry level hooks.

star-szr’s picture

This does sound good overall (was just discussing this with a colleague last week) but the scope in the current issue summary sounds too big and vague IMO. I don't think right now most hook_theme would need a class, that should be optional I think, or use the standard pattern we used when replacing other hooks like these (like hook_menu for example).

Can we just start with a straight conversion (with BC)? That or we need more information I think. Thanks!

dawehner’s picture

This does sound good overall (was just discussing this with a colleague last week) but the scope in the current issue summary sounds too big and vague IMO. I don't think right now most hook_theme would need a class, that should be optional I think, or use the standard pattern we used when replacing other hooks like these (like hook_menu for example).

Yeah I totally believe we want to do the same as for things like routes, just move the discovery from hook_theme() to a yaml file and done.

hatuhay’s picture

Looking from a frontend point of view I see to mayor improvements:

YAML declaration

Using something like:

block__clean:
  label: Clean Wrapper
  type: block
  category: Block
  configuration:
    path: templates/clean
    base hook: block
    render element: elements
  1. Easier and D8 standard way to declare themes.
  2. Declare usual configuration parameters.
  3. Add extra information for Admin UI purposes.

Theme declaration repository

  1. Allow modules and themes to easily access 'declared themes'.
  2. Theme declarations are handled on a standard class (example: Style), so methods could be applied to extend them.

User case

In my case what I needed to achieve is to allow frontend developers to select a theme wrapper for blocks, directly on the block configuration form Block Styles and allow modules and themes to declare new theme wrappers.

To do this I programmed this module Styles API doing something in my understanding should be done by CORE.

On a first stage, both YAML and hook_theme() should coexist with a programmed depreciation deadline for hook_theme().

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

simon georges’s picture

Status: Active » Closed (duplicate)