AMPTestLibrary.php in Accelerated Mobile Pages (AMP) 8.2
File
src/Controller/AMPTestLibrary.php
View source
<?php
namespace Drupal\amp\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\amp\Service\AMPService;
class AMPTestLibrary extends ControllerBase {
protected $amp;
public function __construct(AMPService $amp_utilities) {
$this->amp = $amp_utilities
->createAMPConverter();
}
public static function create(ContainerInterface $container) {
return new static($container
->get('amp.utilities'));
}
public function hello() {
$html_header = PHP_EOL . PHP_EOL . 'OUTPUT HTML' . PHP_EOL;
$html_header .= '-------------' . PHP_EOL;
$html = '<p><a href="javascript:run();">Run</a></p>' . PHP_EOL . '<p><a style="margin: 2px;" href="http://www.cnn.com" target="_parent">CNN</a></p>' . PHP_EOL . '<p><a href="http://www.bbcnews.com" target="_blank">BBC</a></p>' . PHP_EOL . '<p><INPUT type="submit" value="submit"></p>' . PHP_EOL . '<p>This is a <!-- test comment -->sample <div onmouseover="hello();">sample</div> paragraph</p>';
$this->amp
->loadHtml($html);
$amp_html = htmlspecialchars($this->amp
->convertToAmpHtml());
$original_html = PHP_EOL . PHP_EOL . 'ORIGINAL TEST HTML INPUT' . PHP_EOL;
$original_html .= '-------------------------' . PHP_EOL;
$original_html .= htmlspecialchars($html);
return [
'#type' => 'markup',
'#markup' => "<h3>The Library is working fine</h3><pre>{$html_header} {$amp_html} {$original_html}" . $this->amp
->warningsHumanHtml() . "</pre>",
];
}
}