本文整理汇总了PHP中Pim\Component\Catalog\Repository\AttributeRepositoryInterface::find方法的典型用法代码示例。如果您正苦于以下问题:PHP AttributeRepositoryInterface::find方法的具体用法?PHP AttributeRepositoryInterface::find怎么用?PHP AttributeRepositoryInterface::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Component\Catalog\Repository\AttributeRepositoryInterface
的用法示例。
在下文中一共展示了AttributeRepositoryInterface::find方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: removeAttributeAction
/**
* 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()]));
}
}
示例2: findAttributeOr404
/**
* 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;
}
示例3: findAttributeOr404
/**
* @param int $id
*
* @return AttributeInterface
*/
protected function findAttributeOr404($id)
{
$result = $this->attributeRepo->find($id);
if (!$result) {
throw new NotFoundHttpException('Attribute not found');
}
return $result;
}
示例4: getAttribute
/**
* 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;
}
示例5: findAttributeOr404
/**
* @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;
}
示例6: findAttributeOr404
/**
* 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;
}
示例7: findAttributeOr404
/**
* 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;
}
示例8: findAttributeOr404
/**
* 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;
}
示例9: sortAction
/**
* 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);
}