In my example, routes are checked to determine the theme, but you can add whatever logic you may need. If no other implementations selects a theme, the default will select a theme. Drupal has its own default implementation.If determineActiveTheme returns a theme name, Drupal will use this theme, and no further implementations are called.If determineActiveTheme returns null, Drupal moves on to the next implementation.If the applies method returns true, Drupal calls the determineActiveTheme method in the same implementation.If the applies method returns false, Drupal moves on to the next implementation.All implementations begin to be called in priority order, from the highest to the lowest.When is comes time for Drupal to render your page and select a theme, it looks for all classes that implement ThemeNegotiatorInterface.There are no limits on the Sub-theming: Using Stable/Stable 9 as a base theme Themes may extend the Stable themes to ensure their generated markup is not changed by Drupal updates. The higher the priority, the sooner Drupal will call your class logic. Creating sub-themes Sub-themes are just like any other theme, with one difference: They inherit the parent theme's resources. The tag priority tells Drupal how important this class is in relation to other ThemeNegotiatorInterface implementations in your project.The tag name theme_negotiator tells Drupal that this is a class that implements ThemeNegotiatorInterface, and should be used to determine the theme in the current request.Use Drupal\Core\Theme\ThemeNegotiatorInterface Ĭlass ThemeNegotiator implements ThemeNegotiatorInterface Use Drupal\Core\Routing\RouteMatchInterface * Contains \Drupal\jcmodule\Theme\ThemeNegotiator To start, take a look at the documentation, and create a class that implements the interface. More on multiple implementations and how Drupal "chains" these implementations will be discussed later. A typical usage pattern would be to add an implementation to a module that requires a certain theme for specific pages, for example administration pages included in a module. You can create more than one implementation. Whether it is something simple like controlling the theme for user profile pages, or something more complex like switching themes depending on a user's role, using this interface can make the process simple and very flexible. ![]() Drupal 8's ThemeNegotiatorInterface provides a way for developers to create their own management class that decides which theme should go with which content.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |