Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
83bdbd50
Commit
83bdbd50
authored
Apr 08, 2014
by
webchick
Browse files
Issue
#2235125
by tstoeckler: Use DataDefinition::addConstraint() instead of ::setConstraints().
parent
fc6b814e
Changes
4
Hide whitespace changes
Inline
Side-by-side
core/lib/Drupal/Core/TypedData/DataDefinition.php
View file @
83bdbd50
...
...
@@ -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
;
...
...
core/modules/comment/lib/Drupal/comment/Entity/Comment.php
View file @
83bdbd50
...
...
@@ -252,7 +252,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
'default_value'
=>
''
,
'max_length'
=>
60
,
))
->
set
Constraint
s
(
array
(
'CommentName'
=>
array
())
)
;
->
add
Constraint
(
'CommentName'
,
array
());
$fields
[
'mail'
]
=
FieldDefinition
::
create
(
'email'
)
->
setLabel
(
t
(
'Email'
))
...
...
core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListTextItem.php
View file @
83bdbd50
...
...
@@ -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'
))
->
set
Constraint
s
(
$constraints
);
->
add
Constraint
(
'Length'
,
array
(
'max'
=>
255
)
);
return
$properties
;
}
...
...
core/modules/user/user.module
View file @
83bdbd50
...
...
@@ -339,7 +339,7 @@ function user_load_by_name($name) {
*/
function
user_validate_name
(
$name
)
{
$definition
=
DataDefinition
::
create
(
'string'
)
->
set
Constraint
s
(
array
(
'UserName'
=>
array
())
)
;
->
add
Constraint
(
'UserName'
,
array
());
$data
=
\
Drupal
::
typedDataManager
()
->
create
(
$definition
);
$data
->
setValue
(
$name
);
$violations
=
$data
->
validate
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment