class AmpNegotiator in Accelerated Mobile Pages (AMP) 8.2
Same name and namespace in other branches
- 8.3 src/Theme/AmpNegotiator.php \Drupal\amp\Theme\AmpNegotiator
- 8 src/Theme/AmpNegotiator.php \Drupal\amp\Theme\AmpNegotiator
Sets the active theme on amp pages.
Hierarchy
- class \Drupal\Core\DependencyInjection\ServiceProviderBase implements ServiceModifierInterface, ServiceProviderInterface
- 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 14
Namespace
Drupal\amp\ThemeView source
class AmpNegotiator extends ServiceProviderBase implements ThemeNegotiatorInterface {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* AmpContext.
*
* @var \Drupal\amp\Routing\AmpContext
*/
protected $ampContext;
/**
* Creates a new AmpNegotiator instance.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The config factory.
* @param \Drupal\amp\Routing\AmpContext $ampContext
* The AmpContext.
*/
public function __construct(ConfigFactoryInterface $configFactory, AmpContext $ampContext) {
$this->configFactory = $configFactory;
$this->ampContext = $ampContext;
}
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $routeMatch) {
// See if this route and object are AMP, without checking the active theme.
$is_amp_route = $this->ampContext
->isAmpRoute($routeMatch, NULL, FALSE);
if ($is_amp_route) {
// Disable big pipe on AMP pages.
// @todo Rely on https://www.drupal.org/node/2729441 instead, when it is
// resolved.
$routeMatch
->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 | AmpContext. | |
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. | |
ServiceProviderBase:: |
public | function |
Modifies existing service definitions. Overrides ServiceModifierInterface:: |
5 |
ServiceProviderBase:: |
public | function |
Registers services to the container. Overrides ServiceProviderInterface:: |
1 |