/** * Create attribute * * @param Request $request * * @Template("PimEnrichBundle:Attribute:form.html.twig") * @AclAncestor("pim_enrich_attribute_create") * * @return array */ public function createAction(Request $request) { $attributeType = $request->get('attribute_type'); $attributeTypes = $this->registry->getAliases(); if (!$attributeType || !is_string($attributeType) || !in_array($attributeType, $attributeTypes)) { return new RedirectResponse($this->router->generate('pim_enrich_attribute_index')); } $attribute = $this->factory->createAttribute($attributeType); if ($this->attributeHandler->process($attribute)) { $this->request->getSession()->getFlashBag()->add('success', new Message('flash.attribute.created')); return new RedirectResponse($this->router->generate('pim_enrich_attribute_edit', ['id' => $attribute->getId()])); } return ['form' => $this->attributeForm->createView(), 'locales' => $this->localeRepository->getActivatedLocaleCodes(), 'disabledLocales' => $this->localeRepository->findBy(['activated' => false]), 'measures' => $this->measuresConfig, 'attributeType' => $attributeType]; }
function let(AttributeTypeRegistry $registry, AddAttributeTypeRelatedFieldsSubscriber $subscriber, FormBuilderInterface $builder) { $registry->getAliases()->willReturn(['text', 'number', 'email']); $registry->getSortedAliases()->willReturn(['text' => 'text', 'number' => 'number', 'email' => 'email']); $this->beConstructedWith($registry, $subscriber, 'Pim\\Bundle\\CatalogBundle\\Entity\\AttributeTranslation', 'Pim\\Bundle\\CatalogBundle\\Entity\\Attribute', 'Pim\\Bundle\\CatalogBundle\\Entity\\AttributeGroup'); }