Skip to content

Commit

Permalink
Update Extension for Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
bobdenotter committed Nov 23, 2019
1 parent c16e39d commit 4890792
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
21 changes: 21 additions & 0 deletions src/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace AcmeCorp\ReferenceExtension;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

class Controller extends AbstractController
{
public function index($name = 'foo'): Response
{
$context = [
'title' => 'AcmeCorp Reference Extension',
'name' => $name,
];

return $this->render('@reference-extension/page.html.twig', $context);
}
}
43 changes: 37 additions & 6 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace AcmeCorp\ReferenceExtension;

use Bolt\Extension\BaseExtension;
use Symfony\Component\Routing\Route;

class Extension extends BaseExtension
{
Expand All @@ -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
{
}
}
2 changes: 1 addition & 1 deletion src/ReferenceWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 4890792

Please sign in to comment.