You are here

class AmpNegotiator in Accelerated Mobile Pages (AMP) 8.2

Same name and namespace in other branches
  1. 8.3 src/Theme/AmpNegotiator.php \Drupal\amp\Theme\AmpNegotiator
  2. 8 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 14

Namespace

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

Namesort descending Modifiers Type Description Overrides
AmpNegotiator::$ampContext protected property AmpContext.
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.
ServiceProviderBase::alter public function Modifies existing service definitions. Overrides ServiceModifierInterface::alter 5
ServiceProviderBase::register public function Registers services to the container. Overrides ServiceProviderInterface::register 1