/** * {@inheritDoc} */ public function getConfigurationForGrid($name) { $gridName = $this->nameStrategy->parseGridName($name); $result = $this->configurationProvider->getConfiguration($gridName); $gridScope = $this->nameStrategy->parseGridScope($name); if ($gridScope) { $result->offsetSet('scope', $gridScope); } return $result; }
/** * @param DatagridConfiguration $configuration * @param string $gridName * * @return DatagridConfiguration */ public function extendConfiguration(DatagridConfiguration $configuration, $gridName) { $gridConfiguration = $this->configurationProvider->getConfiguration($gridName); $scopes = array_diff(array_keys($gridConfiguration->getIterator()->getArrayCopy()), ['name']); foreach ($scopes as $scope) { $path = sprintf('[%s]', $scope); $additionalParams = $gridConfiguration->offsetGetByPath($path); $baseParams = $configuration->offsetGetByPath($path, []); if (!is_array($additionalParams) || !is_array($baseParams)) { continue; } $configuration->offsetSetByPath($path, ArrayUtils::arrayMergeRecursiveDistinct($baseParams, $additionalParams)); } return $configuration; }
/** * @param DatagridConfiguration $configuration * @param string $gridName * * @return DatagridConfiguration */ public function extendConfiguration(DatagridConfiguration $configuration, $gridName) { $gridConfiguration = $this->configurationProvider->getConfiguration($gridName); $basicAlias = $configuration->offsetGetByPath('[source][query][from][0][alias]'); foreach ($this->pathsToFix as $path) { $forFix = $gridConfiguration->offsetGetByPath($path); if ($forFix) { $gridConfiguration->offsetSetByPath($path, $this->fixMixinAlias($basicAlias, $forFix)); } } $scopes = array_diff(array_keys($gridConfiguration->getIterator()->getArrayCopy()), ['name']); foreach ($scopes as $scope) { $path = sprintf('[%s]', $scope); $additionalParams = $gridConfiguration->offsetGetByPath($path); $baseParams = $configuration->offsetGetByPath($path, []); if (!is_array($additionalParams) || !is_array($baseParams)) { continue; } $configuration->offsetSetByPath($path, self::arrayMergeRecursiveAppendDistinct($baseParams, $additionalParams)); } return $configuration; }
/** * Get grid configuration based on marketing list type. * * Get segments or concrete entity grid configuration by marketing list type and entity. * This configuration will be used as marketing list items grid configuration. * * @param string $gridName * @return DatagridConfiguration */ public function getConfiguration($gridName) { if (empty($this->configuration[$gridName])) { $marketingListId = $this->helper->getMarketingListIdByGridName($gridName); $marketingList = $this->helper->getMarketingList($marketingListId); if (!$marketingList) { throw new \RuntimeException(sprintf('Marketing List with id "%s" not found.', $marketingListId)); } // Get configuration based on marketing list type if ($marketingList->isManual()) { $concreteGridName = $this->getEntityGridName($marketingList->getEntity()); } else { $postfix = str_replace(self::GRID_PREFIX . $marketingList->getId(), '', $gridName); $concreteGridName = Segment::GRID_PREFIX . $marketingList->getSegment()->getId() . $postfix; } $concreteGridConfiguration = $this->chainConfigurationProvider->getConfiguration($concreteGridName); // Reset configured name to current gridName for further usage in Listener and Extension $concreteGridConfiguration->offsetSetByPath(self::GRID_NAME_OFFSET, $gridName); $this->configuration[$gridName] = $concreteGridConfiguration; } return $this->configuration[$gridName]; }
/** * @param string $gridName * @param array $existingParameters * @param array $additionalParameters * @param array $expectedParameters * * @dataProvider extendConfigurationDataProvider */ public function testExtendConfiguration($gridName, array $existingParameters, array $additionalParameters, array $expectedParameters) { $this->configProvider->expects($this->once())->method('getConfiguration')->will($this->returnValue(DatagridConfiguration::create($additionalParameters))); $this->assertEquals(DatagridConfiguration::create($expectedParameters)->toArray(), $this->helper->extendConfiguration(DatagridConfiguration::create($existingParameters), $gridName)->toArray()); }
/** * {@inheritDoc} */ public function getConfigurationForGrid($name) { return $this->configurationProvider->getConfiguration($name); }