I have created custom type field with custom field settings, attached custom constraint successfully called its validator.
The question how to get the field settings values in the validate function, below code sample may explain
/**
* Validates the CustomCheckConstraint.
*/
class CustomCheckConstraintValidator extends ConstraintValidator {
protected $context;
public function validate($data, Constraint $constraint) {
//$data parameter holds the field value
//how could I get the field settings here and validate the value based on
}
}
//attached constraint here
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('integer')
->setLabel(t('type'))
->addConstraint('CustomCheck')
->setRequired(TRUE);
return $properties;
}
Edit: After berdir answer
now the $data variable is an object holds the whole filedType object value and settings.
The problem is I couldn't get the field settings from getSettings() function returns
Error: Call to protected method
The same error occurs when I tried to send field settings value from propertyDefinitions function