You are here

public static function AmpProcessedText::preRenderAmpText in Accelerated Mobile Pages (AMP) 8

Same name and namespace in other branches
  1. 8.3 src/Element/AmpProcessedText.php \Drupal\amp\Element\AmpProcessedText::preRenderAmpText()
  2. 8.2 src/Element/AmpProcessedText.php \Drupal\amp\Element\AmpProcessedText::preRenderAmpText()

Pre-render callback: Processes the amp markup and attaches libraries.

File

src/Element/AmpProcessedText.php, line 70
Contains \Drupal\amp\Element\AmpProcessedText.

Class

AmpProcessedText
Provides an amp-processed text render element.

Namespace

Drupal\amp\Element

Code

public static function preRenderAmpText($element) {

  /** @var AMPService $amp_service */
  $amp_service = \Drupal::getContainer()
    ->get('amp.utilities');

  /** @var AMP $amp */
  $amp = $amp_service
    ->createAMPConverter();
  $amp
    ->loadHtml($element['#markup']);
  $element['#markup'] = $amp
    ->convertToAmpHtml();
  $warning_message = "<pre>" . $amp
    ->warningsHumanHtml() . "</pre>";
  if (self::warningsOn()) {
    $element['#markup'] .= $warning_message;
  }
  if (!empty($amp
    ->getComponentJs())) {
    $element['#attached']['library'] = $amp_service
      ->addComponentLibraries($amp
      ->getComponentJs());
  }
  return $element;
}