/**
  * Remove an attribute
  *
  * @param int $familyId
  * @param int $attributeId
  *
  * @AclAncestor("pim_enrich_family_edit_attributes")
  *
  * @throws DeleteException
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function removeAttributeAction($familyId, $attributeId)
 {
     $family = $this->familyRepository->find($familyId);
     if (null === $family) {
         throw new NotFoundHttpException(sprintf('%s entity not found', $this->familyClass));
     }
     $attribute = $this->attributeRepo->find($attributeId);
     if (null === $attribute) {
         throw new NotFoundHttpException(sprintf('%s entity not found', $this->attributeClass));
     }
     if (false === $family->hasAttribute($attribute)) {
         throw new DeleteException($this->translator->trans('flash.family.attribute not found'));
     } elseif (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) {
         throw new DeleteException($this->translator->trans('flash.family.identifier not removable'));
     } elseif ($attribute === $family->getAttributeAsLabel()) {
         throw new DeleteException($this->translator->trans('flash.family.label attribute not removable'));
     } else {
         $family->removeAttribute($attribute);
         foreach ($family->getAttributeRequirements() as $requirement) {
             if ($requirement->getAttribute() === $attribute) {
                 $family->removeAttributeRequirement($requirement);
                 $this->doctrine->getManagerForClass(ClassUtils::getClass($requirement))->remove($requirement);
             }
         }
         $this->familySaver->save($family);
     }
     if ($this->request->isXmlHttpRequest()) {
         return new Response('', 204);
     } else {
         return new RedirectResponse($this->router->generate('pim_enrich_family_edit', ['id' => $family->getId()]));
     }
 }
 /**
  * Find an attribute by its id or return a 404 response
  *
  * @param int $id the attribute id
  *
  * @throws NotFoundHttpException
  *
  * @return AttributeInterface
  */
 protected function findAttributeOr404($id)
 {
     $attribute = $this->attributeRepository->find($id);
     if (!$attribute) {
         throw new NotFoundHttpException(sprintf('Attribute with id %d could not be found.', $id));
     }
     return $attribute;
 }
 /**
  * @param int $id
  *
  * @return AttributeInterface
  */
 protected function findAttributeOr404($id)
 {
     $result = $this->attributeRepo->find($id);
     if (!$result) {
         throw new NotFoundHttpException('Attribute not found');
     }
     return $result;
 }
 /**
  * Get an attribute or throw an exception
  *
  * @param int $id
  *
  * @throws EntityNotFoundException
  *
  * @return AttributeInterface
  *
  * @deprecated will be removed in 1.5 please use AttributeRepositoryInterface->find()
  */
 public function getAttribute($id)
 {
     $attribute = $this->repository->find($id);
     if (null === $attribute) {
         throw new EntityNotFoundException();
     }
     return $attribute;
 }
 /**
  * @param int $id
  *
  * @return AttributeInterface
  */
 protected function findAttributeOr404($id)
 {
     $result = $this->attributeRepo->find($id);
     if (!$result) {
         throw $this->createNotFoundException(sprintf('Attribute not found'));
     }
     return $result;
 }
 /**
  * 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;
 }
 /**
  * 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('Attribute %s not found', $id));
     }
     return $attribute;
 }
 /**
  * Find an attribute or throw a 404
  *
  * @param int $id The id of the attribute
  *
  * @throws NotFoundHttpException
  *
  * @return AttributeInterface
  */
 protected function findAttributeOr404($id)
 {
     try {
         $result = $this->attributeRepository->find($id);
     } catch (EntityNotFoundException $e) {
         throw new NotFoundHttpException($e->getMessage());
     }
     return $result;
 }
 /**
  * Edit AttributeInterface sort order
  *
  * @param Request $request
  *
  * @AclAncestor("pim_enrich_attribute_sort")
  *
  * @return Response
  */
 public function sortAction(Request $request)
 {
     if (!$request->isXmlHttpRequest()) {
         return $this->redirectToRoute('pim_enrich_attribute_index');
     }
     $data = $request->request->all();
     if (!empty($data)) {
         $attributes = [];
         foreach ($data as $id => $sort) {
             $attribute = $this->attributeRepository->find((int) $id);
             if ($attribute) {
                 $attribute->setSortOrder((int) $sort);
                 $attributes[] = $attribute;
             }
         }
         $this->attributeSaver->saveAll($attributes);
         return new Response(1);
     }
     return new Response(0);
 }