class CropTypeMachineNameValidationConstraintValidator in Crop API 8.2
Same name and namespace in other branches
- 8 src/Plugin/Validation/Constraint/CropTypeMachineNameValidationConstraintValidator.php \Drupal\crop\Plugin\Validation\Constraint\CropTypeMachineNameValidationConstraintValidator
Checks if the crop type is valid.
Hierarchy
- class \Drupal\crop\Plugin\Validation\Constraint\CropTypeMachineNameValidationConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator
Expanded class hierarchy of CropTypeMachineNameValidationConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ CropTypeMachineNameValidationConstraintValidator.php, line 11
Namespace
Drupal\crop\Plugin\Validation\ConstraintView source
class CropTypeMachineNameValidationConstraintValidator extends ConstraintValidator {
/**
* Validator 2.5 and upwards compatible execution context.
*
* @var \Symfony\Component\Validator\Context\ExecutionContextInterface
*/
protected $context;
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) {
// '0' is invalid, since elsewhere we check it using empty().
/** @var \Drupal\crop\Entity\CropType $value */
if (trim($value
->id()) == '0') {
$this->context
->buildViolation($constraint->message)
->atPath('id')
->addViolation();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CropTypeMachineNameValidationConstraintValidator:: |
protected | property | Validator 2.5 and upwards compatible execution context. | |
CropTypeMachineNameValidationConstraintValidator:: |
public | function | Checks if the passed value is valid. |