ThemeNegotiatorInterface.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Drupal\Core\Theme;
  3. use Drupal\Core\Routing\RouteMatchInterface;
  4. /**
  5. * Defines an interface for classes which determine the active theme.
  6. *
  7. * To set the active theme, create a new service tagged with 'theme_negotiator'
  8. * (see the theme.negotiator.admin_theme service in user.services.yml for an
  9. * example). Your service class needs to implement this interface.
  10. *
  11. * If you are setting a theme which is closely tied to the functionality of a
  12. * particular page or set of pages (such that the page might not function
  13. * correctly if a different theme is used), make sure to set the priority on
  14. * the service to a high number so that it is not accidentally overridden by
  15. * other theme negotiators. By convention, a priority of "1000" is used in
  16. * these cases; see \Drupal\Core\Theme\AjaxBasePageNegotiator and
  17. * core.services.yml for an example.
  18. */
  19. interface ThemeNegotiatorInterface {
  20. /**
  21. * Whether this theme negotiator should be used to set the theme.
  22. *
  23. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  24. * The current route match object.
  25. *
  26. * @return bool
  27. * TRUE if this negotiator should be used or FALSE to let other negotiators
  28. * decide.
  29. */
  30. public function applies(RouteMatchInterface $route_match);
  31. /**
  32. * Determine the active theme for the request.
  33. *
  34. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  35. * The current route match object.
  36. *
  37. * @return string|null
  38. * The name of the theme, or NULL if other negotiators, like the configured
  39. * default one, should be used instead.
  40. */
  41. public function determineActiveTheme(RouteMatchInterface $route_match);
  42. }