本文整理匯總了PHP中Sonata\AdminBundle\Validator\ErrorElement::addViolation方法的典型用法代碼示例。如果您正苦於以下問題:PHP ErrorElement::addViolation方法的具體用法?PHP ErrorElement::addViolation怎麽用?PHP ErrorElement::addViolation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sonata\AdminBundle\Validator\ErrorElement
的用法示例。
在下文中一共展示了ErrorElement::addViolation方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validate
/**
* @param \Sonata\AdminBundle\Validator\ErrorElement $errorElement
* @param $object
* @return void
*/
public function validate(ErrorElement $errorElement, $object)
{
if (!$object->getUrl()) {
$this->cmsManager->getPageManager()->fixUrl($object);
}
$page = $this->cmsManager->getPageManager()->getPageByUrl($object->getUrl());
if (!$page) {
$page = $this->cmsManager->getPageManager()->getPageByUrl(substr($object->getUrl(), -1) == '/' ? substr($object->getUrl(), 0, -1) : $object->getUrl() . '/');
}
if ($page && $page->getId() != $object->getId()) {
$errorElement->addViolation($this->trans('error.uniq_url', array('%url%' => $object->getUrl())));
}
}
示例2: validateFormBasketElement
/**
* {@inheritdoc}
*/
public function validateFormBasketElement(ErrorElement $errorElement, BasketElementInterface $basketElement, BasketInterface $basket)
{
// the item is flagged as deleted, no need to validate the item
if ($basketElement->getDelete() || 0 === $basketElement->getQuantity()) {
return;
}
// refresh the product from the database
$product = $basketElement->getProduct();
// check if the product is still in database
if (!$product) {
$errorElement->addViolation('product_not_available');
return;
}
// check if the product is still enabled
if (!$basketElement->getProduct()->getEnabled()) {
$errorElement->addViolation('product_not_enabled');
return;
}
// check if the quantity is numeric
if (!is_numeric($basketElement->getQuantity())) {
$errorElement->with('quantity')->addViolation('product_quantity_not_numeric')->end();
return;
}
$errorElement->with('quantity')->assertRange(array('min' => 1, 'max' => $this->getStockAvailable($basketElement->getProduct()), 'minMessage' => 'basket_quantity_limit_min', 'maxMessage' => 'basket_quantity_limit_max'))->end();
}