本文整理匯總了PHP中Symfony\Component\Validator\Constraint::getBundleOption方法的典型用法代碼示例。如果您正苦於以下問題:PHP Constraint::getBundleOption方法的具體用法?PHP Constraint::getBundleOption怎麽用?PHP Constraint::getBundleOption使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Validator\Constraint
的用法示例。
在下文中一共展示了Constraint::getBundleOption方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validate
/**
* {@inheritdoc}
*/
public function validate($entity, Constraint $constraint)
{
if (!isset($entity)) {
return;
}
if (!in_array($entity->bundle(), $constraint->getBundleOption())) {
$this->context->addViolation($constraint->message, array('%bundle' => implode(', ', $constraint->getBundleOption())));
}
}
示例2: validate
/**
* {@inheritdoc}
*/
public function validate($entity_adapter, Constraint $constraint)
{
if (!isset($entity_adapter)) {
return;
}
// @todo The $entity_adapter parameter passed to this function should always
// be a typed data object, but due to a bug, the unwrapped entity is
// passed for the computed entity property of entity reference fields.
// Remove this after fixing that in https://www.drupal.org/node/2346373.
if (!$entity_adapter instanceof TypedDataInterface) {
$entity = $entity_adapter;
} else {
$entity = $entity_adapter->getValue();
}
if (!in_array($entity->bundle(), $constraint->getBundleOption())) {
$this->context->addViolation($constraint->message, array('%bundle' => implode(', ', $constraint->getBundleOption())));
}
}