/** * Find an attribute * * @param int $id * * @throws NotFoundHttpException * * @return AttributeInterface */ protected function findAttributeOr404($id) { $attribute = $this->attributeRepository->find($id); if (null === $attribute) { throw new NotFoundHttpException(sprintf('%s entity not found', $this->attributeManager->getAttributeClass())); } return $attribute; }
/** * Ensure at least one option for the attribute * * @param AbstractAttribute $entity */ protected function ensureOneOption(AbstractAttribute $entity) { $selectTypes = array('pim_catalog_simpleselect', 'pim_catalog_multiselect'); if (in_array($entity->getAttributeType(), $selectTypes) && count($entity->getOptions()) < 1) { $option = $this->attributeManager->createAttributeOption(); $option->setTranslatable(true); $entity->addOption($option); } }
/** * Find an attribute or throw a 404 * * @param integer $id The id of the attribute * * @throws NotFoundHttpException * @return AttributeInterface */ protected function findAttributeOr404($id) { try { $result = $this->attributeManager->getAttribute($id); } catch (EntityNotFoundException $e) { throw new NotFoundHttpException($e->getMessage()); } return $result; }
/** * Find an attribute * * @param integer $id * * @return AbstractAttribute * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ protected function findAttributeOr404($id) { return $this->findOr404($this->attributeManager->getAttributeClass(), $id); }
/** * {@inheritdoc} */ protected function createEntity($class, array $data) { return $this->attributeManager->createAttribute($data['type']); }
/** * Remove an attribute. * * @param AbstractAttribute $attribute */ public function remove(AbstractAttribute $attribute) { $this->baseAttributeManager->remove($attribute); }
/** * Return available frontend type * * @return array */ protected function getAttributeTypeChoices() { return $this->attributeManager->getAttributeTypes(); }
function let(AttributeManager $manager, AddAttributeTypeRelatedFieldsSubscriber $subscriber, FormBuilderInterface $builder) { $manager->getAttributeTypes()->willReturn(['text', 'number', 'email']); $this->beConstructedWith($manager, $subscriber, 'Pim\\Bundle\\CatalogBundle\\Entity\\AttributeTranslation', 'Pim\\Bundle\\CatalogBundle\\Entity\\Attribute', 'Pim\\Bundle\\CatalogBundle\\Entity\\AttributeGroup'); }