Commit 83bdbd50 authored by webchick's avatar webchick

Issue #2235125 by tstoeckler: Use DataDefinition::addConstraint() instead of ::setConstraints().

parent fc6b814e
......@@ -275,13 +275,17 @@ public function getConstraint($constraint_name) {
/**
* Sets the array of validation constraints.
*
* See \Drupal\Core\TypedData\TypedDataManager::getConstraints() for details.
* NOTE: This will override any previously set constraints. In most cases
* DataDefinition::addConstraint() should be used instead.
*
* @param array $constraints
* The array of constraints.
* The array of constraints. See
* \Drupal\Core\TypedData\TypedDataManager::getConstraints() for details.
*
* @return static
* The object itself for chaining.
* @return $this
*
* @see \Drupal\Core\TypedData\DataDefinition::addConstraint()
* @see \Drupal\Core\TypedData\DataDefinition::getConstraints()
*/
public function setConstraints(array $constraints) {
$this->definition['constraints'] = $constraints;
......
......@@ -252,7 +252,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
'default_value' => '',
'max_length' => 60,
))
->setConstraints(array('CommentName' => array()));
->addConstraint('CommentName', array());
$fields['mail'] = FieldDefinition::create('email')
->setLabel(t('Email'))
......
......@@ -27,10 +27,9 @@ class ListTextItem extends ListItemBase {
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldDefinitionInterface $field_definition) {
$constraints = array('Length' => array('max' => 255));
$properties['value'] = DataDefinition::create('string')
->setLabel(t('Text value'))
->setConstraints($constraints);
->addConstraint('Length', array('max' => 255));
return $properties;
}
......
......@@ -339,7 +339,7 @@ function user_load_by_name($name) {
*/
function user_validate_name($name) {
$definition = DataDefinition::create('string')
->setConstraints(array('UserName' => array()));
->addConstraint('UserName', array());
$data = \Drupal::typedDataManager()->create($definition);
$data->setValue($name);
$violations = $data->validate();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment