class AmpNegotiator in Accelerated Mobile Pages (AMP) 8
Same name and namespace in other branches
- 8.3 src/Theme/AmpNegotiator.php \Drupal\amp\Theme\AmpNegotiator
- 8.2 src/Theme/AmpNegotiator.php \Drupal\amp\Theme\AmpNegotiator
Sets the active theme on amp pages.
Hierarchy
- class \Drupal\amp\Theme\AmpNegotiator implements ThemeNegotiatorInterface
Expanded class hierarchy of AmpNegotiator
1 string reference to 'AmpNegotiator'
1 service uses AmpNegotiator
File
- src/
Theme/ AmpNegotiator.php, line 18 - Contains \Drupal\amp\Theme\AmpNegotiator.
Namespace
Drupal\amp\ThemeView source
class AmpNegotiator implements ThemeNegotiatorInterface {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The route amp context to determine whether a route is an amp one.
*
* @var \Drupal\amp\Routing\AmpContext
*/
protected $ampContext;
/**
* Creates a new AmpNegotiator instance.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\amp\Routing\AmpContext $amp_context
* The route amp context to determine whether the route is an amp one.
*/
public function __construct(ConfigFactoryInterface $config_factory, AmpContext $amp_context) {
$this->configFactory = $config_factory;
$this->ampContext = $amp_context;
}
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
$is_amp_route = $this->ampContext
->isAmpRoute($route_match
->getRouteObject());
if ($is_amp_route) {
// Disable big pipe on AMP pages.
// @todo Rely on https://www.drupal.org/node/2729441 instead, when it is
// resolved.
$route_match
->getRouteObject()
->setOption('_no_big_pipe', TRUE);
}
return $is_amp_route;
}
/**
* {@inheritdoc}
*/
public function determineActiveTheme(RouteMatchInterface $route_match) {
return $this->configFactory
->get('amp.theme')
->get('amptheme');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AmpNegotiator:: |
protected | property | The route amp context to determine whether a route is an amp one. | |
AmpNegotiator:: |
protected | property | The config factory. | |
AmpNegotiator:: |
public | function |
Whether this theme negotiator should be used to set the theme. Overrides ThemeNegotiatorInterface:: |
|
AmpNegotiator:: |
public | function |
Determine the active theme for the request. Overrides ThemeNegotiatorInterface:: |
|
AmpNegotiator:: |
public | function | Creates a new AmpNegotiator instance. |