Skip to content

Commit

Permalink
Merge 3.x into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Nov 29, 2017
2 parents 36764c3 + 59d2bc4 commit d33b72d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Expand Up @@ -45,18 +45,18 @@ matrix:
- php: '7.1'
env: SYMFONY=3.3.*
- php: '7.1'
env: SYMFONY='dev-master as 3.3'
env: SYMFONY='dev-master as 3.3.x-dev'
- php: '7.1'
env: SONATA_CORE=3.*
- php: '7.1'
env: SONATA_CORE='dev-master as 3'
env: SONATA_CORE='dev-master as 3.x-dev'
- php: '7.1'
env: SYMFONY_DEPRECATIONS_HELPER=0
allow_failures:
- php: nightly
- env: SYMFONY_DEPRECATIONS_HELPER=0
- env: SYMFONY='dev-master as 3.3'
- env: SONATA_CORE='dev-master as 3'
- env: SYMFONY='dev-master as 3.3.x-dev'
- env: SONATA_CORE='dev-master as 3.x-dev'

before_install:
- git remote add upstream ${UPSTREAM_URL} && git fetch --all
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.7.0](https://github.com/sonata-project/SonataBlockBundle/compare/3.7.0...3.8.0) - 2017-11-28
### Changed
- menuRegistry parameter in `Sonata\BlockBundle\Block\Service\MenuBlockService` to be allowed the type of array

## [3.6.0](https://github.com/sonata-project/SonataBlockBundle/compare/3.6.0...3.7.0) - 2017-11-27
### Changed
- Rollback to PHP 5.6 as minimum support.
Expand Down
32 changes: 19 additions & 13 deletions src/Block/Service/MenuBlockService.php
Expand Up @@ -15,6 +15,7 @@
use Knp\Menu\Provider\MenuProviderInterface;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Menu\MenuRegistry;
use Sonata\BlockBundle\Menu\MenuRegistryInterface;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\CoreBundle\Model\Metadata;
Expand Down Expand Up @@ -48,26 +49,35 @@ class MenuBlockService extends AbstractAdminBlockService
protected $menuRegistry;

/**
* @param string $name
* @param EngineInterface $templating
* @param MenuProviderInterface $menuProvider
* @param MenuRegistryInterface|array $menuRegistry
* @param string $name
* @param EngineInterface $templating
* @param MenuProviderInterface $menuProvider
* @param MenuRegistryInterface|null $menuRegistry
*/
public function __construct($name, EngineInterface $templating, MenuProviderInterface $menuProvider, $menuRegistry)
public function __construct($name, EngineInterface $templating, MenuProviderInterface $menuProvider, $menuRegistry = null)
{
parent::__construct($name, $templating);

$this->menuProvider = $menuProvider;

// NEXT_MAJOR: change the constructor parameter to MenuManagerInterface and remove the following condition
if ($menuRegistry instanceof MenuRegistryInterface) {
$this->menuRegistry = $menuRegistry;
} else {
} elseif (is_null($menuRegistry)) {
$this->menuRegistry = new MenuRegistry();
} elseif (is_array($menuRegistry)) { //NEXT_MAJOR: Remove this case
@trigger_error(
'Initializing '.__CLASS__.' with an array parameter is deprecated since 3.3 and will be removed in 4.0.',
E_USER_DEPRECATED
);
$this->menus = $menuRegistry;
$this->menuRegistry = new MenuRegistry();
foreach ($menuRegistry as $menu) {
$this->menuRegistry->add($menu);
}
} else {
throw new \InvalidArgumentException(sprintf(
'MenuRegistry must be either null or instance of %s',
MenuRegistryInterface::class
));
}
}

Expand Down Expand Up @@ -153,11 +163,7 @@ protected function getFormSettingsKeys()
'required' => false,
];

$choices = $this->menus;

if (0 == count($choices)) {
$choices = $this->menuRegistry->getAliasNames();
}
$choices = $this->menuRegistry->getAliasNames();

$choices = array_flip($choices);

Expand Down

0 comments on commit d33b72d

Please sign in to comment.