function let(DatagridConfiguration $configuration, ConfigurationRegistry $registry)
 {
     $registry->getConfiguration('pim_catalog_identifier')->willReturn(['column' => ['identifier_config']]);
     $registry->getConfiguration('pim_catalog_text')->willReturn(['column' => ['text_config']]);
     $configuration->offsetGetByPath(sprintf('[%s]', FormatterConfiguration::COLUMNS_KEY))->willReturn(['family' => ['family_config']]);
     $this->beConstructedWith($registry);
 }
 /**
  * {@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);
 }
 /**
  * Prepare dynamic columns, ie columns for attributes
  */
 protected function prepareAttributesColumns()
 {
     $path = sprintf(self::SOURCE_PATH, self::USEABLE_ATTRIBUTES_KEY);
     $attributes = $this->configuration->offsetGetByPath($path);
     $attributes = $attributes === null ? [] : $attributes;
     $this->identifierColumn = [];
     $this->attributesColumns = [];
     foreach ($attributes as $attributeCode => $attribute) {
         $attributeType = $attribute['attributeType'];
         $attributeTypeConf = $this->registry->getConfiguration($attributeType);
         if (!$attributeTypeConf || !isset($attributeTypeConf['column'])) {
             throw new \LogicException(sprintf('Attribute type %s must be configured to display attribute %s as grid column', $attributeType, $attributeCode));
         }
         if ($attributeTypeConf && $attributeTypeConf['column']) {
             $columnConfig = $attributeTypeConf['column'];
             $columnConfig = $columnConfig + ['label' => $attribute['label'], 'order' => $attribute['sortOrder'], 'group' => $attribute['group'], 'groupOrder' => $attribute['groupOrder']];
             if (AttributeTypes::IDENTIFIER === $attributeType) {
                 $this->identifierColumn[$attributeCode] = $columnConfig;
             } else {
                 $this->attributesColumns[$attributeCode] = $columnConfig;
             }
         }
     }
     uasort($this->attributesColumns, function ($col1, $col2) {
         return strcmp($col1['label'], $col2['label']);
     });
 }
 function let(DatagridConfiguration $configuration, ConfigurationRegistry $registry, ProductManager $manager)
 {
     $attributes = ['sku' => ['code' => 'sku', 'attributeType' => 'pim_catalog_identifier'], 'name' => ['code' => 'name', 'attributeType' => 'pim_catalog_text']];
     $configuration->offsetGetByPath(sprintf('[source][%s]', ContextConfigurator::USEABLE_ATTRIBUTES_KEY))->willReturn($attributes);
     $configuration->offsetGetByPath(sprintf('[%s]', FormatterConfiguration::COLUMNS_KEY))->willReturn(['family' => ['family_config'], 'sku' => [], 'name' => []]);
     $registry->getConfiguration('pim_catalog_identifier')->willReturn(['column' => ['identifier_config'], 'sorter' => 'flexible_field']);
     $this->beConstructedWith($registry, $manager);
 }
 /**
  * Add sorters for attributes used as columns
  */
 protected function addAttributeSorters()
 {
     $path = sprintf(self::SOURCE_PATH, self::USEABLE_ATTRIBUTES_KEY);
     $attributes = $this->configuration->offsetGetByPath($path);
     $attributes = $attributes === null ? [] : $attributes;
     $columns = $this->configuration->offsetGetByPath(sprintf('[%s]', FormatterConfiguration::COLUMNS_KEY));
     foreach ($attributes as $attributeCode => $attribute) {
         $attributeType = $attribute['attributeType'];
         $attributeTypeConf = $this->registry->getConfiguration($attributeType);
         $columnExists = isset($columns[$attributeCode]);
         if (!$attributeTypeConf || !isset($attributeTypeConf['column'])) {
             throw new \LogicException(sprintf('Attribute type %s must be configured to display sorter for attribute %s', $attributeType, $attributeCode));
         }
         if ($columnExists && $attributeTypeConf && $attributeTypeConf['column']) {
             if (isset($attributeTypeConf['sorter'])) {
                 $this->configuration->offsetSetByPath(sprintf('%s[%s]', OrmSorterConfiguration::COLUMNS_PATH, $attributeCode), [PropertyInterface::DATA_NAME_KEY => $attributeCode, 'sorter' => $attributeTypeConf['sorter']]);
             }
         }
     }
 }