Added constraint validator to taxonomy.settings:terms_per_page_admin
Closes #3395563
Merge request reports
Activity
3 namespace Drupal\Core\Validation\Plugin\Validation\Constraint; 4 5 use Symfony\Component\Validator\Constraints\Type; 6 use Symfony\Component\Validator\Constraints\TypeValidator; 7 8 /** 9 * Type constraint. 10 * 11 * Extends Symfony's Type constraint to validate types. 12 * 13 * @Constraint( 14 * id = "Type", 15 * label = @Translation("Type constraint", context = "Validation"), 16 * ) 17 */ 18 class TypeConstraint extends Type { @lauriii is right: we don't need this constraint.
\Drupal\Core\Validation\Plugin\Validation\Constraint\PrimitiveTypeConstraintValidator::validate()already handles this.Why? Because when config is validated against its schema, it is always converted to TypedData.
See
PrimitiveTypeConstraintValidatorTestandConfigSchemaTest::testConfigSaveWithSchema(). Try changing the'integer' => '100',test value to something else, and you'll see it gets cast to an integer anyway. Changing that may be something we some day want to do, but is very out of scope here.changed this line in version 6 of the diff
13 13 terms_per_page_admin: 14 14 type: integer 15 15 label: 'Number of terms per page' 16 constraints: 17 Type: 18 type: 'integer' - Comment on lines +17 to +18
Great, thanks

But should be
min: 1to force higher than 0?About
is_numeric(), acording to php documentation (https://www.php.net/manual/en/function.is-numeric.php), that function will return true for float.But should be
min: 1to force higher than 0?Yes, added on the last commit. Looking at where this is used, I do not see any special meaning associated with 0, as in other places, so yes

About is_numeric and float, yes, that is the case. The way I think about constraints is as composable blocks, complementing each other. In that way, the Type plugin checks the language type, and the Range plugin check the minimal value here.
changed this line in version 6 of the diff
13 13 terms_per_page_admin: 14 14 type: integer 15 15 label: 'Number of terms per page' 16 constraints: 17 PrimitiveType: [] This is not necessary.
type: integerautomatically gets this constraint applied, like I explained earlier. Search the codebase for'PrimitiveType'(exactly this string, including the single quotes), and you'll find the place where it gets automagically added.If we'd need this here, we'd need this on literally every config schema definition (!!!) for a scalar (string/int/float/bool or specialization of any of these) value!
changed this line in version 7 of the diff
added 128 commits
-
4dc8dfd0...82c59f84 - 121 commits from branch
project:11.x - 20ca4a8d - Added constraint validator to taxonomy.settings:terms_per_page_admin
- fc21ca7a - Added new constraint to check types.
- 21518b23 - Fixed unused use statement
- f33256e3 - Apply 1 suggestion(s) to 1 file(s)
- 12c38130 - Set minimal term list size to 1
- 2b092ac2 - Removed unnecessary constrain.
- 949ed985 - Removed constraint of PrimitiveType.
Toggle commit list-
4dc8dfd0...82c59f84 - 121 commits from branch
mentioned in merge request !5675
