/**
  * {@inheritdoc}
  */
 public function process($attribute)
 {
     $context = ['locales' => $this->localeManager->getActiveCodes()];
     $flatAttribute = ['type' => $attribute->getAttributeType(), 'code' => $attribute->getCode()] + $this->transNormalizer->normalize($attribute, null, $context);
     $flatAttribute = array_merge($flatAttribute, ['group' => $attribute->getGroup() ? $attribute->getGroup()->getCode() : null, 'unique' => (int) $attribute->isUnique(), 'useable_as_grid_filter' => (int) $attribute->isUseableAsGridFilter(), 'allowed_extensions' => implode(self::ITEM_SEPARATOR, $attribute->getAllowedExtensions()), 'metric_family' => $attribute->getMetricFamily(), 'default_metric_unit' => $attribute->getDefaultMetricUnit(), 'localizable' => (int) $attribute->isLocalizable(), 'scopable' => (int) $attribute->isScopable(), 'families' => $this->getAttributeFamilyCodes($attribute)]);
     return $flatAttribute;
 }
 /**
  * @param ProductInterface $product
  *
  * @return array
  */
 protected function getLabels(ProductInterface $product)
 {
     $labels = [];
     foreach ($this->localeManager->getActiveCodes() as $localeCode) {
         $labels[$localeCode] = $product->getLabel($localeCode);
     }
     return ['label' => $labels];
 }
 /**
  * Prepare attributes list for CSV headers
  *
  * @param array $attributesList
  *
  * @return array
  */
 protected function prepareAttributesList(array $attributesList)
 {
     $scopeCode = $this->catalogContext->getScopeCode();
     $localeCodes = $this->localeManager->getActiveCodes();
     $fieldsList = array();
     foreach ($attributesList as $attribute) {
         $attCode = $attribute->getCode();
         if ($attribute->isLocalizable() && $attribute->isScopable()) {
             foreach ($localeCodes as $localeCode) {
                 $fieldsList[] = sprintf('%s-%s-%s', $attCode, $localeCode, $scopeCode);
             }
         } elseif ($attribute->isLocalizable()) {
             foreach ($localeCodes as $localeCode) {
                 $fieldsList[] = sprintf('%s-%s', $attCode, $localeCode);
             }
         } elseif ($attribute->isScopable()) {
             $fieldsList[] = sprintf('%s-%s', $attCode, $scopeCode);
         } elseif ($attribute->getAttributeType() === 'pim_catalog_identifier') {
             array_unshift($fieldsList, $attCode);
         } elseif ($attribute->getAttributeType() === 'pim_catalog_price_collection') {
             foreach ($this->currencyManager->getActiveCodes() as $currencyCode) {
                 $fieldsList[] = sprintf('%s-%s', $attCode, $currencyCode);
             }
         } else {
             $fieldsList[] = $attCode;
         }
     }
     return $fieldsList;
 }
 /**
  * Prepare attributes list for CSV headers
  *
  * @param array $attributesList
  *
  * @return array
  */
 protected function prepareAttributesList(array $attributesList)
 {
     $scopeCode = $this->catalogContext->getScopeCode();
     $localeCodes = $this->localeManager->getActiveCodes();
     $fieldsList = [];
     foreach ($attributesList as $attribute) {
         $attCode = $attribute->getCode();
         if ($attribute->isLocalizable() && $attribute->isScopable()) {
             foreach ($localeCodes as $localeCode) {
                 $fieldsList[] = sprintf('%s-%s-%s', $attCode, $localeCode, $scopeCode);
             }
         } elseif ($attribute->isLocalizable()) {
             foreach ($localeCodes as $localeCode) {
                 $fieldsList[] = sprintf('%s-%s', $attCode, $localeCode);
             }
         } elseif ($attribute->isScopable()) {
             $fieldsList[] = sprintf('%s-%s', $attCode, $scopeCode);
         } elseif (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) {
             array_unshift($fieldsList, $attCode);
         } elseif (AttributeTypes::PRICE_COLLECTION === $attribute->getAttributeType()) {
             foreach ($this->currencyManager->getActiveCodes() as $currencyCode) {
                 $fieldsList[] = sprintf('%s-%s', $attCode, $currencyCode);
             }
         } else {
             $fieldsList[] = $attCode;
         }
     }
     return $fieldsList;
 }
 /**
  * Edit attribute form
  *
  * @param Request $request
  * @param int     $id
  *
  * @Template("PimEnrichBundle:Attribute:form.html.twig")
  * @AclAncestor("pim_enrich_attribute_edit")
  *
  * @return array
  */
 public function editAction(Request $request, $id)
 {
     $attribute = $this->findAttributeOr404($id);
     if ($this->attributeHandler->process($attribute)) {
         $this->addFlash('success', 'flash.attribute.updated');
         return $this->redirectToRoute('pim_enrich_attribute_edit', ['id' => $attribute->getId()]);
     }
     return ['form' => $this->attributeForm->createView(), 'locales' => $this->localeManager->getActiveCodes(), 'disabledLocales' => $this->localeManager->getDisabledLocales(), 'measures' => $this->measuresConfig, 'created' => $this->versionManager->getOldestLogEntry($attribute), 'updated' => $this->versionManager->getNewestLogEntry($attribute)];
 }
 /**
  * Get activated locales as choices
  *
  * @return string[]
  */
 public function getActivatedLocaleChoices()
 {
     $translateIn = $this->getCurrentLocaleCode();
     $activeCodes = $this->localeManager->getActiveCodes();
     $results = [];
     foreach ($activeCodes as $activeCode) {
         $results[$activeCode] = $this->getLocaleLabel($activeCode, $translateIn);
     }
     return $results;
 }
 /**
  * Get active codes
  *
  * @return string[]
  */
 public function getActiveCodes()
 {
     return $this->baseLocaleManager->getActiveCodes();
 }