class AjaxBasePageNegotiator implements ThemeNegotiatorInterface (View source)

Defines a theme negotiator that deals with the active theme on ajax requests.

Many different pages can invoke an Ajax request to a generic Ajax path. It is almost always desired for an Ajax response to be rendered using the same theme as the base page, because most themes are built with the assumption that they control the entire page, so if the CSS for two themes are both loaded for a given page, they may conflict with each other. For example, Bartik is Drupal's default theme, and Seven is Drupal's default administration theme. Depending on whether the "Use the administration theme when editing or creating content" checkbox is checked, the node edit form may be displayed in either theme, but the Ajax response to the Field module's "Add another item" button should be rendered using the same theme as the rest of the page.

Properties

protected CsrfTokenGenerator $csrfGenerator

The CSRF token generator.

protected ConfigFactoryInterface $configFactory

The config factory.

protected RequestStack $requestStack

The request stack.

Methods

__construct(CsrfTokenGenerator $token_generator, ConfigFactoryInterface $config_factory, RequestStack $request_stack)

Constructs a new AjaxBasePageNegotiator.

bool
applies(RouteMatchInterface $route_match)

Whether this theme negotiator should be used to set the theme.

string|null
determineActiveTheme(RouteMatchInterface $route_match)

Determine the active theme for the request.

Details

__construct(CsrfTokenGenerator $token_generator, ConfigFactoryInterface $config_factory, RequestStack $request_stack)

Constructs a new AjaxBasePageNegotiator.

Parameters

CsrfTokenGenerator $token_generator

The CSRF token generator.

ConfigFactoryInterface $config_factory

The config factory.

RequestStack $request_stack

The request stack used to retrieve the current request.

bool applies(RouteMatchInterface $route_match)

Whether this theme negotiator should be used to set the theme.

Parameters

RouteMatchInterface $route_match

The current route match object.

Return Value

bool

TRUE if this negotiator should be used or FALSE to let other negotiators decide.

string|null determineActiveTheme(RouteMatchInterface $route_match)

Determine the active theme for the request.

Parameters

RouteMatchInterface $route_match

The current route match object.

Return Value

string|null

The name of the theme, or NULL if other negotiators, like the configured default one, should be used instead.