コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function process($family)
 {
     $configuration = $this->getJobConfiguration();
     if (!array_key_exists('actions', $configuration)) {
         throw new InvalidArgumentException('Missing configuration for \'actions\'.');
     }
     $actions = $configuration['actions'];
     foreach ($actions as $action) {
         $attribute = $this->attributeRepository->findOneByIdentifier($action['attribute_code']);
         $channel = $this->channelRepository->findOneByIdentifier($action['channel_code']);
         $isRequired = $action['is_required'];
         $family->addAttribute($attribute);
         $family->addAttributeRequirement($this->factory->createAttributeRequirement($attribute, $channel, $isRequired));
     }
     return $family;
 }
コード例 #2
0
 /**
  * @param AttributeInterface $attribute
  * @param string             $channelCode
  *
  * @throws \InvalidArgumentException
  *
  * @return AttributeRequirementInterface
  */
 protected function createAttributeRequirement(AttributeInterface $attribute, $channelCode)
 {
     $channel = $this->channelRepository->findOneByIdentifier($channelCode);
     if (null === $channel) {
         throw new \InvalidArgumentException(sprintf('Channel with "%s" code does not exist', $channelCode));
     }
     return $this->attrRequiFactory->createAttributeRequirement($attribute, $channel, true);
 }
コード例 #3
0
 /**
  * Check the consistency of the field with channel associated
  *
  * @param AttributeInterface $attribute
  * @param string             $fieldName
  * @param array              $attributeInfo
  *
  * @throws \InvalidArgumentException
  */
 protected function checkFieldNameLocaleByChannel(AttributeInterface $attribute, $fieldName, array $attributeInfo)
 {
     if ($attribute->isScopable() && $attribute->isLocalizable() && isset($attributeInfo['scope_code']) && isset($attributeInfo['locale_code'])) {
         $channel = $this->channelRepository->findOneByIdentifier($attributeInfo['scope_code']);
         $locale = $this->localeRepository->findOneByIdentifier($attributeInfo['locale_code']);
         if ($channel !== null && $locale !== null && !$channel->hasLocale($locale)) {
             throw new \InvalidArgumentException(sprintf('The locale "%s" of the field "%s" is not available in scope "%s"', $attributeInfo['locale_code'], $fieldName, $attributeInfo['scope_code']));
         }
     }
 }
コード例 #4
0
 /**
  * @param FamilyInterface    $family
  * @param AttributeInterface $attribute
  * @param string             $channelCode
  *
  * @return AttributeRequirementInterface
  */
 protected function createAttributeRequirement(FamilyInterface $family, AttributeInterface $attribute, $channelCode)
 {
     $channel = $this->channelRepository->findOneByIdentifier($channelCode);
     if (null === $channel) {
         throw new \InvalidArgumentException(sprintf('Channel with "%s" code does not exist', $channelCode));
     }
     $requirement = $this->requirementRepo->findOneBy(['attribute' => $attribute->getId(), 'channel' => $channel->getId(), 'family' => $family->getId()]);
     if (null === $requirement) {
         $requirement = $this->attrRequiFactory->createAttributeRequirement($attribute, $channel, true);
     }
     return $requirement;
 }
コード例 #5
0
 /**
  * @param FamilyInterface $family
  * @param array           $data
  */
 protected function setAttributeRequirements(FamilyInterface $family, array $data)
 {
     $requirements = [];
     foreach ($data as $channelCode => $attributeCodes) {
         foreach ($attributeCodes as $attributeCode) {
             if (null !== ($attribute = $this->attributeRepository->findOneByIdentifier($attributeCode))) {
                 if (null !== ($channel = $this->channelRepository->findOneByIdentifier($channelCode))) {
                     $requirements[] = $this->attrRequiFactory->createAttributeRequirement($attribute, $channel, true);
                 } else {
                     throw new \InvalidArgumentException(sprintf('Channel with "%s" code does not exist', $channelCode));
                 }
             } else {
                 throw new \InvalidArgumentException(sprintf('Attribute with "%s" code does not exist', $attributeCode));
             }
         }
     }
     $family->setAttributeRequirements($requirements);
 }
コード例 #6
0
 /**
  * @param AttributeInterface $attribute
  * @param array              $values
  *
  * @throws ObjectNotFoundException
  *
  * @return array
  */
 protected function getNewValuesData(AttributeInterface $attribute, array $values)
 {
     $newValues = [];
     foreach ($values as $value) {
         $acceptValue = true;
         if (null !== $value['locale']) {
             $isAuthorizedOnLocale = !$this->objectFilter->filterObject($this->getLocale($value['locale']), 'pim.internal_api.locale.edit');
             $isEditableOnLocale = $attribute->isLocaleSpecific() ? in_array($value['locale'], $attribute->getLocaleSpecificCodes()) : true;
             $acceptValue = $isAuthorizedOnLocale && $isEditableOnLocale;
         }
         if ($attribute->isScopable() && $acceptValue) {
             $channel = $this->channelRepository->findOneByIdentifier($value['scope']);
             if (null === $channel) {
                 $acceptValue = false;
             }
         }
         if ($acceptValue) {
             $newValues[] = $value;
         }
     }
     return $newValues;
 }