/** * 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); }
/** * 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; }
/** * 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; }
/** * @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; }
/** * @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); }
/** * @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; }