1 | <?php |
||
2 | namespace DorsetDigital\SilverStripeAmpPages; |
||
3 | |||
4 | use SilverStripe\Core\Extension; |
||
5 | use SilverStripe\Control\Controller; |
||
6 | use SilverStripe\View\Requirements; |
||
7 | |||
8 | class AmpPagesControllerExtension extends Extension |
||
9 | { |
||
10 | |||
11 | private static $allowed_actions = ['amp']; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
12 | |||
13 | public function amp() |
||
14 | { |
||
15 | Requirements::clear(); |
||
16 | $this->addAmpStyles(); |
||
17 | $controller = Controller::curr(); |
||
18 | $class = $controller->ClassName; |
||
19 | return $this->owner->renderWith([$class."_amp", "Amp"]); |
||
20 | } |
||
21 | |||
22 | private function addAmpStyles() |
||
23 | { |
||
24 | $css = null; |
||
25 | $cssFiles = AmpPagesRequirementsExtension::getAmpCSSFiles(); |
||
26 | foreach ($cssFiles as $themeCSSPath) { |
||
27 | $fullCSSPath = BASE_PATH.DIRECTORY_SEPARATOR.$themeCSSPath; |
||
28 | if (is_file($fullCSSPath)) { |
||
29 | $css .= file_get_contents($fullCSSPath); |
||
30 | } |
||
31 | } |
||
32 | $tag = '<style amp-custom>'.$css.'</style>'; |
||
33 | Requirements::insertHeadTags($tag); |
||
34 | } |
||
35 | } |
||
36 |