/** * @param ConfigureMenuEvent $event */ public function onNavigationConfigure(ConfigureMenuEvent $event) { foreach ((array) $this->settings->getSettings(SettingsProvider::DATA_PATH) as $setting) { if (!$this->state->isEntityEnabled($setting['name'])) { continue; } foreach ($setting['navigation_items'] as $item) { $navigateArray = explode('.', $item); $menu = $event->getMenu(); if ($menu->getName() !== $navigateArray[0]) { continue; } $navigateArrayCount = count($navigateArray); for ($i = 1; $i < $navigateArrayCount; $i++) { if ($menu->getChild($navigateArray[$i])) { /** redefinition of variable $menu */ $menu = $menu->getChild($navigateArray[$i]); } if ($menu && !$menu->isDisplayed()) { $menu->setDisplay(true); } } } } }
/** * @dataProvider exclusionProvider * * @param bool $expected * @param bool $isChannelEntity * @param array $dependentDataMap * @param array $enabledEntityMap */ public function testIsRelationExcluded($expected, $isChannelEntity, $dependentDataMap = [], $enabledEntityMap = []) { $this->settingsProvider->expects($this->any())->method('isChannelEntity')->will($this->returnValueMap([[self::TEST_MAIN_ENTITY_NAME, true], [self::TEST_ENTITY_NAME, $isChannelEntity]])); $this->settingsProvider->expects($this->any())->method('getDependentEntityData')->will($this->returnValueMap($dependentDataMap)); $this->stateProvider->expects($this->any())->method('isEntityEnabled')->will($this->returnValueMap($enabledEntityMap)); $classMetadataMock = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock(); $classMetadataMock->expects($this->once())->method('getName')->will($this->returnValue(self::TEST_MAIN_ENTITY_NAME)); $classMetadataMock->expects($this->once())->method('getAssociationTargetClass')->with($this->equalTo(self::TEST_ASSOC_NAME))->will($this->returnValue(self::TEST_ENTITY_NAME)); $this->assertSame($expected, $this->exclusionProvider->isIgnoredRelation($classMetadataMock, self::TEST_ASSOC_NAME)); }
/** * {@inheritDoc} */ public function isConditionAllowed($context) { if (null !== $this->channel) { /** @var Channel $dataChannel */ $dataChannel = $this->resolveValue($context, $this->channel, false); $entities = $dataChannel->getEntities(); $allowed = count(array_intersect($this->entities, $entities)) === count($this->entities); } else { $allowed = $this->stateProvider->isEntitiesEnabledInSomeChannel($this->entities); } return $allowed; }
/** * {@inheritDoc} */ public function isAllowed($context, Collection $errors = null) { if (null !== $this->channel) { /** @var Channel $dataChannel */ $dataChannel = $this->contextAccessor->getValue($context, $this->channel); $entities = $dataChannel->getEntities(); $allowed = count(array_intersect($this->entities, $entities)) === count($this->entities); } else { $allowed = $this->stateProvider->isEntitiesEnabledInSomeChannel($this->entities); } return $allowed; }
/** * @param string $method * @param array $args * * @throws \RuntimeException * @throws \LogicException * @return bool */ public function __call($method, $args) { if (!$this->stateProvider) { throw new \RuntimeException('Provider configured incorrectly, missed "state provider"'); } if (preg_match('#(isEntity)(\\w+)(Enabled)#', $method, $matches)) { $entityName = rtrim($this->namespace, '\\') . '\\' . $matches[2]; if (class_exists($entityName)) { return $this->stateProvider->isEntityEnabled($entityName); } else { throw new \LogicException(sprintf('Unable to check state for "%s". Class does not exist', $entityName)); } } }
/** * @param string $entityFQCN entity full class name * * @return bool */ protected function isIncludedByChannels($entityFQCN) { if ($this->settingsProvider->isChannelEntity($entityFQCN)) { return $this->stateProvider->isEntityEnabled($entityFQCN); } elseif ($this->settingsProvider->isDependentOnChannelEntity($entityFQCN)) { $enabled = false; $dependencies = $this->settingsProvider->getDependentEntityData($entityFQCN); foreach ($dependencies as $entityName) { $enabled |= $this->stateProvider->isEntityEnabled($entityName); } return $enabled; } return true; }
/** * @dataProvider navigationConfigureDataProvider * * @param array $settings * @param bool $isEnabled * @param bool $expectedResult */ public function testOnNavigationConfigure($settings, $isEnabled, $expectedResult) { $factory = new MenuFactory(); $this->resolver->expects($this->any())->method('resolve')->will($this->returnArgument(0)); $this->state->expects($this->once())->method('isEntityEnabled')->will($this->returnValue($isEnabled)); $settingsProvider = new SettingsProvider($settings, $this->resolver); $listener = new NavigationListener($settingsProvider, $this->state); $menu = new MenuItem('test_menu', $factory); $salesTab = new MenuItem('sales_tab', $factory); $salesTab->addChild('test_item')->setDisplay(false); $menu->addChild($salesTab); $this->assertFalse($salesTab->getChild('test_item')->isDisplayed()); $eventData = new ConfigureMenuEvent($factory, $menu); $listener->onNavigationConfigure($eventData); $this->assertEquals($expectedResult, $salesTab->getChild('test_item')->isDisplayed()); }