Skip to content

Commit

Permalink
Fix a crash when Netgen Tags Bundle is installed but not activated
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed Dec 21, 2017
1 parent 157362a commit a7159f4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Netgen Admin UI Bundle changelog

## 2.1.1 (21.12.2017)

* Fix a crash when Netgen Tags Bundle is installed but not activated

## 2.1.0 (14.12.2017)

* Mark all services as private/public for compatibility with Symfony 3.4
Expand Down
36 changes: 27 additions & 9 deletions DependencyInjection/NetgenAdminUIExtension.php
Expand Up @@ -30,17 +30,17 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('controllers.yml');
$loader->load('services.yml');

$activatedBundles = array_keys($container->getParameter('kernel.bundles'));
$activatedBundles = $container->getParameter('kernel.bundles');

if (!in_array('EzCoreExtraBundle', $activatedBundles, true)) {
if (!array_key_exists('EzCoreExtraBundle', $activatedBundles)) {
throw new RuntimeException('Netgen Admin UI Bundle requires EzCoreExtraBundle (lolautruche/ez-core-extra-bundle) to be activated to work properly.');
}

if (class_exists('Netgen\TagsBundle\Version') && TagsBundleVersion::MAJOR_VERSION >= 3) {
if ($this->hasTags($activatedBundles)) {
$loader->load('tags/services.yml');
}

if ($this->hasLayouts($container)) {
if ($this->hasLayouts($activatedBundles)) {
$loader->load('layouts/controllers.yml');
}

Expand All @@ -61,7 +61,7 @@ public function prepend(ContainerBuilder $container)
'framework/twig.yml' => 'twig',
);

if ($this->hasLayouts($container)) {
if ($this->hasLayouts($container->getParameter('kernel.bundles'))) {
$configs['layouts/view.yml'] = 'netgen_block_manager';
}

Expand All @@ -76,11 +76,11 @@ public function prepend(ContainerBuilder $container)
/**
* Returns if Netgen Layouts is active or not.
*
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
* @param array $activatedBundles
*
* @return bool
*/
protected function hasLayouts(ContainerBuilder $container)
protected function hasLayouts(array $activatedBundles)
{
if (!class_exists('Netgen\BlockManager\Version')) {
return false;
Expand All @@ -90,8 +90,26 @@ protected function hasLayouts(ContainerBuilder $container)
return false;
}

$activatedBundles = $container->getParameter('kernel.bundles');

return array_key_exists('NetgenBlockManagerBundle', $activatedBundles);
}

/**
* Returns if Netgen Tags v3+ is active or not.
*
* @param array $activatedBundles
*
* @return bool
*/
protected function hasTags(array $activatedBundles)
{
if (!class_exists('Netgen\TagsBundle\Version')) {
return false;
}

if (TagsBundleVersion::MAJOR_VERSION < 3) {
return false;
}

return array_key_exists('NetgenTagsBundle', $activatedBundles);
}
}

0 comments on commit a7159f4

Please sign in to comment.