CropTypeMachineNameValidationConstraintValidator.php in Crop API 8.2
Same filename and directory in other branches
Namespace
Drupal\crop\Plugin\Validation\ConstraintFile
src/Plugin/Validation/Constraint/CropTypeMachineNameValidationConstraintValidator.phpView source
<?php
namespace Drupal\crop\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Checks if the crop type is valid.
*/
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();
}
}
}
Classes
Name | Description |
---|---|
CropTypeMachineNameValidationConstraintValidator | Checks if the crop type is valid. |