/**
  * {@inheritdoc}
  */
 public function configure(DatagridConfiguration $configuration)
 {
     $attributes = $configuration->offsetGet(self::SOURCE_KEY)[self::USEABLE_ATTRIBUTES_KEY];
     $attributes = $attributes === null ? [] : $attributes;
     $displayedFilters = [];
     foreach ($attributes as $attributeCode => $attribute) {
         if (!$attribute['useableAsGridFilter']) {
             continue;
         }
         $attributeType = $attribute['attributeType'];
         $attributeTypeConf = $this->registry->getConfiguration($attributeType);
         if (!$attributeTypeConf || !isset($attributeTypeConf['filter'])) {
             throw new \LogicException(sprintf('Attribute type %s must be configured to allow grid filter on attribute %s', $attributeType, $attributeCode));
         }
         $filterConfig = $attributeTypeConf['filter'];
         $filterConfig = $filterConfig + [ProductFilterUtility::DATA_NAME_KEY => $attributeCode, 'label' => $attribute['label'], 'enabled' => AttributeTypes::IDENTIFIER === $attributeType, 'order' => $attribute['sortOrder'], 'group' => $attribute['group'], 'groupOrder' => $attribute['groupOrder']];
         if (AttributeTypes::METRIC === $attributeType) {
             $filterConfig['family'] = $attribute['metricFamily'];
         }
         $displayedFilters[$attributeCode] = $filterConfig;
     }
     $this->sortFilters($displayedFilters);
     $filters = $configuration->offsetGet(FilterConfiguration::FILTERS_KEY);
     foreach ($displayedFilters as $attributeCode => $filterConfig) {
         $filters['columns'][$attributeCode] = $filterConfig;
     }
     $configuration->offsetSet(FilterConfiguration::FILTERS_KEY, $filters);
 }
 /**
  * Build references data
  *
  * @param DatasourceInterface   $dataSource
  * @param DatagridConfiguration $configuration
  */
 protected function buildReferenceData(DatasourceInterface $dataSource, DatagridConfiguration $configuration)
 {
     $source = $configuration->offsetGet('source');
     $qb = $dataSource->getQueryBuilder();
     foreach ($configuration->offsetGet('columns') as $column => $config) {
         $this->buildQueryBuilder($qb, $source, $column);
     }
 }
 function it_cannot_handle_misconfigured_attribute_type(DatagridConfiguration $configuration, $registry)
 {
     $attributes = ['sku' => ['code' => 'sku', 'label' => 'Sku', 'useableAsGridFilter' => 1, 'attributeType' => 'pim_catalog_identifier', 'sortOrder' => 2, 'group' => 'Foo', 'groupOrder' => 3], 'name' => ['code' => 'name', 'label' => 'Name', 'useableAsGridFilter' => 1, 'attributeType' => 'pim_catalog_text', 'sortOrder' => 4, 'group' => 'Bar', 'groupOrder' => 5]];
     $attributesConf = [ContextConfigurator::USEABLE_ATTRIBUTES_KEY => $attributes];
     $configuration->offsetGet(ContextConfigurator::SOURCE_KEY)->willReturn($attributesConf);
     $registry->getConfiguration('pim_catalog_identifier')->willReturn(['filter' => ['identifier_config']]);
     $registry->getConfiguration('pim_catalog_text')->willReturn([]);
     $this->shouldThrow('\\LogicException')->duringConfigure($configuration);
 }
 function it_applies_when_user_preference_is_filled_and_skip_disallowed($context, UserInterface $user, DatagridInterface $datagrid, Acceptor $acceptor, DatagridConfiguration $config, BuildAfter $event)
 {
     $config->offsetGet('filters')->willReturn(['columns' => ['foo' => [], 'baz' => [], 'scope' => [], 'locale' => []]]);
     $config->offsetSetByPath('[filters][columns][foo][enabled]', true)->shouldBeCalled();
     $config->offsetSetByPath('[filters][columns][baz][enabled]', false)->shouldBeCalled();
     $config->offsetSetByPath('[filters][columns][bar][enabled]', Argument::any())->shouldNotBeCalled();
     $config->offsetSetByPath('[filters][columns][scope][enabled]', Argument::any())->shouldNotBeCalled();
     $config->offsetSetByPath('[filters][columns][locale][enabled]', Argument::any())->shouldNotBeCalled();
     $user->getProductGridFilters()->willReturn(['foo', 'bar']);
     $context->getUser()->willReturn($user);
     $acceptor->getConfig()->willReturn($config);
     $datagrid->getAcceptor()->willReturn($acceptor);
     $event->getDatagrid()->willReturn($datagrid);
     $this->onBuildAfter($event);
 }
 /**
  * @param DatagridConfiguration $config
  *
  * @return array
  */
 protected function getColumnsWithOrder(DatagridConfiguration $config)
 {
     $columnsData = $config->offsetGet(self::COLUMNS_PATH);
     $columnsOrder = $this->columnsHelper->buildColumnsOrder($columnsData);
     $columns = $this->applyColumnsOrderAndRender($columnsData, $columnsOrder);
     return $columns;
 }
示例#6
0
 /**
  * @param DatagridConfiguration $config
  * @param bool                  $default
  *
  * @return array
  */
 protected function getColumnsWithOrder(DatagridConfiguration $config, $default = false)
 {
     if (!$default) {
         $params = $this->getParameters()->get(ParameterBag::ADDITIONAL_PARAMETERS, []);
         $defaultGridView = $this->getDefaultGridView($config->getName());
         if (isset($params['view']) && $defaultGridView && $params['view'] === $defaultGridView->getId()) {
             return $defaultGridView->getColumnsData();
         }
     }
     $columnsData = $config->offsetGet(self::COLUMNS_PATH);
     $columnsOrder = $this->columnsHelper->buildColumnsOrder($columnsData);
     $columns = $this->applyColumnsOrderAndRender($columnsData, $columnsOrder);
     return $columns;
 }