You are here

class AmpNegotiator in Accelerated Mobile Pages (AMP) 8

Same name and namespace in other branches
  1. 8.3 src/Theme/AmpNegotiator.php \Drupal\amp\Theme\AmpNegotiator
  2. 8.2 src/Theme/AmpNegotiator.php \Drupal\amp\Theme\AmpNegotiator

Sets the active theme on amp pages.

Hierarchy

Expanded class hierarchy of AmpNegotiator

1 string reference to 'AmpNegotiator'
amp.services.yml in ./amp.services.yml
amp.services.yml
1 service uses AmpNegotiator
theme.negotiator.amp_theme in ./amp.services.yml
Drupal\amp\Theme\AmpNegotiator

File

src/Theme/AmpNegotiator.php, line 18
Contains \Drupal\amp\Theme\AmpNegotiator.

Namespace

Drupal\amp\Theme
View 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

Namesort descending Modifiers Type Description Overrides
AmpNegotiator::$ampContext protected property The route amp context to determine whether a route is an amp one.
AmpNegotiator::$configFactory protected property The config factory.
AmpNegotiator::applies public function Whether this theme negotiator should be used to set the theme. Overrides ThemeNegotiatorInterface::applies
AmpNegotiator::determineActiveTheme public function Determine the active theme for the request. Overrides ThemeNegotiatorInterface::determineActiveTheme
AmpNegotiator::__construct public function Creates a new AmpNegotiator instance.