Skip to content

Commit

Permalink
Clean up extension loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Gawain Lynch committed Nov 8, 2016
1 parent 33f17d0 commit 0f4102b
Showing 1 changed file with 21 additions and 47 deletions.
68 changes: 21 additions & 47 deletions src/SeoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
use Bolt\Asset\Widget\Widget;
use Bolt\Controller\Zone;
use Bolt\Extension\SimpleExtension;
//use Bolt\Translation\Translator as Trans;
use Silex\Application;

//use Symfony\Component\Translation\Loader as TranslationLoader;

class SeoExtension extends SimpleExtension
{
private $version = 'v0.11.0';
Expand All @@ -23,16 +20,19 @@ public function registerFields()
];
}

/**
* {@inheritdoc}
*/
protected function registerAssets()
{
$seoCss = new Stylesheet();
$seoCss->setFileName('seo.css')->setZone(Zone::BACKEND);

$underscoreJs = new JavaScript();
$underscoreJs->setFilename('underscore-min.js')->setZone(Zone::BACKEND)->setPriority(10);
$underscoreJs->setFileName('underscore-min.js')->setZone(Zone::BACKEND)->setPriority(10);

$backboneJs = new JavaScript();
$backboneJs->setFilename('backbone-min.js')->setZone(Zone::BACKEND)->setPriority(15);
$backboneJs->setFileName('backbone-min.js')->setZone(Zone::BACKEND)->setPriority(15);

$assets = [
$seoCss,
Expand All @@ -48,11 +48,12 @@ protected function registerAssets()
if ($rollthedice < $config['eastereggchance']) {
$widgetObj = new Widget();
$widgetObj
->setZone('backend')
->setLocation('dashboard_aside_middle')
->setCallback([$this, 'backendDashboardWidget'])
->setCallbackArguments([])
->setDefer(false);
->setDefer(false)
->setZone('backend')
->setLocation('dashboard_aside_middle')
;
$assets[] = $widgetObj;
}
}
Expand Down Expand Up @@ -81,12 +82,15 @@ public function backendDashboardWidget()
]);
}

public function registerServices(Application $app)
/**
* {@inheritdoc}
*/
protected function registerServices(Application $app)
{
$app['twig'] = $app->extend(
'twig',
function ($twig) use ($app) {
$seo = new SEO($this->getContainer(), $this->getConfig(), $this->version);
function (\Twig_Environment $twig) use ($app) {
$seo = new SEO($app, $this->getConfig(), $this->version);
$twig->addGlobal('seo', $seo);
$twig->addGlobal('seoconfig', $this->getConfig());

Expand All @@ -95,49 +99,19 @@ function ($twig) use ($app) {
);
}

/**
* {@inheritdoc}
*/
protected function registerTwigPaths()
{
return [
'templates' => ['position' => 'prepend', 'namespace' => 'bolt'],
];
}

public function initialize()
{
$currentUser = $this->app['users']->getCurrentUser();
$currentUserId = $currentUser['id'];

// Set the Permissions for the advanced field to the correct roles.
$this->config['allowed'] = [];
if (!empty($this->config['allow'])) {
foreach ($this->config['allow'] as $key => $field) {
$this->config['allowed'][$key] = false;
foreach ($this->config['allow'][$key] as $role) {
if ($this->app['users']->hasRole($currentUserId, $role)) {
$this->config['allowed'][$key] = true;
break;
}
}
}
}

$this->app['twig']->addGlobal('seoconfig', $this->config);
}

public function before()
{
$this->translationDir = __DIR__ . '/locales/' . substr($this->app['locale'], 0, 2);
if (is_dir($this->translationDir)) {
$iterator = new \DirectoryIterator($this->translationDir);
foreach ($iterator as $fileInfo) {
if ($fileInfo->isFile()) {
$this->app['translator']->addLoader('yml', new TranslationLoader\YamlFileLoader());
$this->app['translator']->addResource('yml', $fileInfo->getRealPath(), $this->app['locale']);
}
}
}
}

/**
* {@inheritdoc}
*/
protected function getDefaultConfig()
{
return [
Expand Down

0 comments on commit 0f4102b

Please sign in to comment.