You are here

class DrupalParsedValidatorRules in Accelerated Mobile Pages (AMP) 8.3

Drupal override of Lullabot\ParsedValidatorRules.

Adds alter hook to rules array.

Hierarchy

Expanded class hierarchy of DrupalParsedValidatorRules

1 file declares its use of DrupalParsedValidatorRules
DrupalAMP.php in src/AMP/DrupalAMP.php

File

src/AMP/DrupalParsedValidatorRules.php, line 13

Namespace

Drupal\amp\AMP
View source
class DrupalParsedValidatorRules extends ParsedValidatorRules {

  /**
   * {@inheritdoc}
   */
  public static function getSingletonParsedValidatorRules() {
    if (!empty(self::$parsed_validator_rules_singleton)) {
      return self::$parsed_validator_rules_singleton;
    }
    else {
      $rules = self::updatedRules();
      self::$parsed_validator_rules_singleton = new self($rules);
      return self::$parsed_validator_rules_singleton;
    }
  }

  /**
   * Adds an alter hook to update AMP rules that might be causing problems.
   *
   * The original code in Lullabot/AMP is out of date with the current AMP
   * specifications. Updating that code is a non-trivial job that may not get
   * done any time soon. This is a work-around to allow changes to the rules.
   *
   * @TODO Add caching.
   *
   * @see https://github.com/Lullabot/amp-library/blob/master/src/Spec/validator-generated.php
   */
  public static function updatedRules() {
    $rules = ValidationRulesFactory::createValidationRules();

    // Allow other modules to alter the rules.
    \Drupal::moduleHandler()
      ->alter('amp_rules', $rules);
    return $rules;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalParsedValidatorRules::getSingletonParsedValidatorRules public static function
DrupalParsedValidatorRules::updatedRules public static function Adds an alter hook to update AMP rules that might be causing problems.