diff --git a/src/Controller.php b/src/Controller.php new file mode 100644 index 0000000..3a039a4 --- /dev/null +++ b/src/Controller.php @@ -0,0 +1,21 @@ + 'AcmeCorp Reference Extension', + 'name' => $name, + ]; + + return $this->render('@reference-extension/page.html.twig', $context); + } +} diff --git a/src/Extension.php b/src/Extension.php index ee96a00..794e43b 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -5,6 +5,7 @@ namespace AcmeCorp\ReferenceExtension; use Bolt\Extension\BaseExtension; +use Symfony\Component\Routing\Route; class Extension extends BaseExtension { @@ -17,17 +18,47 @@ public function getName(): string } /** - * Ran automatically, you can use this method to set up things in your - * extension. + * Add the routes for this extension. + * + * Note: These are cached by Symfony. If you make modifications to this, run + * `bin/console cache:clear` to ensure your routes are parsed. + */ + public function getRoutes(): array + { + return [ + 'reference' => new Route( + '/extensions/reference/{name}', + ['_controller' => 'AcmeCorp\ReferenceExtension\Controller::index'], + ['name' => '[a-zA-Z0-9]+'] + ), + ]; + } + + /** + * Ran automatically, if the current request is in a browser. + * You can use this method to set up things in your extension. * * Note: This runs on every request. Make sure what happens here is quick * and efficient. */ - public function initialize(): void + public function initialize($cli = false): void { - $this->registerWidget(new ReferenceWidget()); - $this->registerTwigExtension(new Twig()); - + $this->addWidget(new ReferenceWidget()); + $this->addTwigExtension(new Twig()); + + $this->addTwigNamespace('reference-extension'); + // $this->registerListener('kernel.response', [new EventListener(), 'handleEvent']); } + + /** + * Ran automatically, if the current request is from the command line (CLI). + * You can use this method to set up things in you extension. + * + * Note: This runs on every request. Make sure what happens here is quick + * and efficient. + */ + public function initializeCli(): void + { + } } diff --git a/src/ReferenceWidget.php b/src/ReferenceWidget.php index 5ab0304..49786a9 100644 --- a/src/ReferenceWidget.php +++ b/src/ReferenceWidget.php @@ -21,7 +21,7 @@ class ReferenceWidget extends BaseWidget implements TwigAware, CacheAware, Stopw protected $name = 'AcmeCorp ReferenceWidget'; protected $target = AdditionalTarget::WIDGET_BACK_DASHBOARD_ASIDE_TOP; protected $priority = 200; - protected $template = '@acmecorp-referencewidget/widget.html.twig'; + protected $template = '@reference-extension/widget.html.twig'; protected $zone = RequestZone::BACKEND; protected $cacheDuration = -1800; }