本文整理汇总了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();
}