/**
  * Gets item by name
  *
  * @param string $itemName
  * @param array  $variables
  *
  * @return array|null
  */
 public function getItem($itemName, array $variables)
 {
     if (!isset($this->placeholders['items'][$itemName])) {
         // the requested item does not exist
         return null;
     }
     $item = $this->placeholders['items'][$itemName];
     if (isset($item['acl'])) {
         if ($this->isGranted($item['acl'])) {
             // remove 'acl' attribute as it is not needed anymore
             unset($item['acl']);
         } else {
             // the access denied for the requested item
             return null;
         }
     }
     if (isset($item['applicable'])) {
         $resolved = $this->resolver->resolve(['applicable' => $item['applicable']], $variables);
         if ($resolved['applicable'] === true) {
             // remove 'applicable' attribute as it is not needed anymore
             unset($item['applicable']);
         } else {
             // the requested item is not applicable in the current context
             return null;
         }
     }
     return $this->resolver->resolve($item, $variables);
 }
Exemple #2
0
 /**
  * Get settings that were collected from channel_configuration config files
  *
  * @param null $section
  *
  * @return array|null
  */
 public function getSettings($section = null)
 {
     if (null === $this->resolvedSettings) {
         $settings = $this->resolvedSettings = $this->resolver->resolve($this->settings);
         $this->resolvedSettings[self::DATA_PATH] = [];
         foreach ($settings[self::DATA_PATH] as $singleEntitySetting) {
             $this->resolvedSettings[self::DATA_PATH][trim($singleEntitySetting['name'])] = $singleEntitySetting;
         }
     }
     if ($section === null) {
         return $this->resolvedSettings;
     } elseif (isset($this->resolvedSettings[$section])) {
         return $this->resolvedSettings[$section];
     }
     return null;
 }
 /**
  * @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());
 }
 /**
  * Get form fields settings
  *
  * @param string $name            - node name that specifies which form settings needed
  * @param string $integrationType - integration type name for applicable check
  *
  * @throws \LogicException
  * @return array
  */
 public function getFormSettings($name, $integrationType)
 {
     $result = $priorities = [];
     if (isset($this->settings[IntegrationConfiguration::FORM_NODE_NAME], $this->settings[IntegrationConfiguration::FORM_NODE_NAME][$name])) {
         $formData = $this->settings[IntegrationConfiguration::FORM_NODE_NAME][$name];
         foreach ($formData as $fieldName => $field) {
             $field = $this->resolver->resolve($field, ['channelType' => $integrationType]);
             // if applicable node not set, then applicable to all
             if ($this->isApplicable($field, $integrationType)) {
                 $priority = isset($field['priority']) ? $field['priority'] : 0;
                 $priorities[] = $priority;
                 $result[$fieldName] = $field;
             }
         }
         array_multisort($priorities, SORT_ASC, $result);
     }
     return $result;
 }
Exemple #5
0
 /**
  * @param $widgetName
  * @param $widgetId
  * @return array
  */
 public function getWidgetItemsData($widgetName, $widgetId)
 {
     $widgetConfig = $this->configProvider->getWidgetConfig($widgetName);
     $widgetOptions = $this->getWidgetOptions($widgetId);
     $items = isset($widgetConfig['data_items']) ? $widgetConfig['data_items'] : [];
     $items = $this->filterWidgets($items, true, $widgetOptions->get('subWidgets', []));
     foreach ($items as $itemName => $config) {
         $items[$itemName]['value'] = $this->resolver->resolve([$config['data_provider']], ['widgetOptions' => $widgetOptions])[0];
     }
     return $items;
 }
 /**
  * @param array|string $conditions
  * @param array $variables
  * @return bool
  */
 protected function resolveApplicable($conditions, array $variables)
 {
     $resolved = true;
     $conditions = (array) $conditions;
     foreach ($conditions as $condition) {
         $resolved = $this->resolver->resolve([self::APPLICABLE => $condition], $variables)[self::APPLICABLE];
         if (!$resolved) {
             break;
         }
     }
     return $resolved;
 }
 public function testAclConditionArraySuccess()
 {
     $items = ['placeholder_item' => ['template' => 'template', 'acl' => ['acl_ancestor1', 'acl_ancestor2']]];
     $variables = ['foo' => 'bar'];
     $provider = $this->createProvider($items);
     $this->securityFacade->expects($this->at(0))->method('isGranted')->with('acl_ancestor1')->will($this->returnValue(true));
     $this->securityFacade->expects($this->at(1))->method('isGranted')->with('acl_ancestor2')->will($this->returnValue(true));
     unset($items['placeholder_item']['acl']);
     $this->resolver->expects($this->at(0))->method('resolve')->with($items['placeholder_item'], $variables)->will($this->returnValue($items['placeholder_item']));
     $actual = $provider->getPlaceholderItems(self::TEST_PLACEHOLDER, $variables);
     unset($items['placeholder_item']['acl']);
     $this->assertSame([$items['placeholder_item']], $actual);
 }
 /**
  * @param ItemInterface $menu
  * @param array         $data
  * @param array         $itemList
  * @param array         $options
  *
  * @return \Knp\Menu\ItemInterface
  */
 private function createFromArray(ItemInterface $menu, array $data, array &$itemList, array $options = array())
 {
     $isAllowed = false;
     foreach ($data as $itemCode => $itemData) {
         $itemData = $this->resolver->resolve($itemData);
         if (!empty($itemList[$itemCode])) {
             $itemOptions = $itemList[$itemCode];
             if (empty($itemOptions['name'])) {
                 $itemOptions['name'] = $itemCode;
             }
             if (!empty($itemData['position'])) {
                 $itemOptions['extras']['position'] = $itemData['position'];
             }
             $this->moveToExtras($itemOptions, 'translateDomain');
             $this->moveToExtras($itemOptions, 'translateParameters');
             $newMenuItem = $menu->addChild($itemOptions['name'], array_merge($itemOptions, $options));
             if (!empty($itemData['children'])) {
                 $this->createFromArray($newMenuItem, $itemData['children'], $itemList, $options);
             }
             $isAllowed = $isAllowed || $newMenuItem->getExtra('isAllowed');
         }
     }
     $menu->setExtra('isAllowed', $isAllowed);
 }
Exemple #9
0
 /**
  * @param $widgetName
  * @param $widgetId
  * @return array
  */
 public function getWidgetItemsData($widgetName, $widgetId)
 {
     $widgetConfig = $this->configProvider->getWidgetConfig($widgetName);
     $widgetOptions = $this->getWidgetOptions($widgetId);
     $items = isset($widgetConfig['data_items']) ? $widgetConfig['data_items'] : [];
     $items = $this->filterWidgets($items);
     if ($this->eventDispatcher->hasListeners(WidgetItemsLoadDataEvent::EVENT_NAME)) {
         $event = new WidgetItemsLoadDataEvent($items, $widgetConfig, $widgetOptions);
         $this->eventDispatcher->dispatch(WidgetItemsLoadDataEvent::EVENT_NAME, $event);
         $items = $event->getItems();
     }
     foreach ($items as $itemName => $config) {
         $items[$itemName]['value'] = $this->resolver->resolve([$config['data_provider']], ['widgetOptions' => $widgetOptions])[0];
     }
     return $items;
 }