Issue #3426309 by Wim Leers, smustgrave: Add config validation for weights (blocks, filters, etc. all use weights)

merge-requests/5106/merge
catch 2024-03-07 19:12:43 +00:00
parent 25697a17e8
commit 9c1e103520
19 changed files with 38 additions and 27 deletions

View File

@ -168,6 +168,17 @@ bytes:
constraints:
Callback: ['\Drupal\Component\Utility\Bytes', 'validateConstraint']
weight:
type: integer
label: 'Weight'
constraints:
Range:
# @see PHP_INT_MIN (32-bit)
min: -2147483648
# @see PHP_INT_MAX (32-bit)
max: 2147483647
FullyValidatable: ~
# Complex extended data types:
# Root of a configuration object.
@ -229,7 +240,7 @@ filter:
type: boolean
label: 'Status'
weight:
type: integer
type: weight
label: 'Weight'
settings:
type: filter_settings.[%parent.id]
@ -483,7 +494,7 @@ display_variant.plugin:
type: required_label
label: 'Label'
weight:
type: integer
type: weight
label: 'Weight'
uuid:
type: uuid

View File

@ -101,7 +101,7 @@ field_formatter.entity_view_display:
type: field_formatter
mapping:
weight:
type: integer
type: weight
label: 'Weight'
region:
type: string
@ -144,7 +144,7 @@ core.entity_form_display.*.*.*:
manager: plugin.manager.field.widget
interface: '\Drupal\Core\Field\WidgetInterface'
weight:
type: integer
type: weight
label: 'Weight'
region:
type: string

View File

@ -16,7 +16,7 @@ core.menu.static_menu_link_overrides:
type: string
label: 'Parent'
weight:
type: integer
type: weight
label: 'Weight'
expanded:
type: boolean

View File

@ -21,7 +21,7 @@ block.block.*:
type: string
label: 'Region'
weight:
type: integer
type: weight
label: 'Weight'
provider:
type: string

View File

@ -143,7 +143,7 @@ config_schema_test.ignore:
type: ignore
label: 'Indescribable'
weight:
type: integer
type: weight
label: 'Weight'
config_schema_test.plugin_types:

View File

@ -10,7 +10,7 @@ config_test_dynamic:
type: label
label: 'Label'
weight:
type: integer
type: weight
label: 'Weight'
style:
type: string

View File

@ -25,7 +25,7 @@ contact.form.*:
type: text
label: 'Auto-reply'
weight:
type: integer
type: weight
label: 'Weight'
message:
type: text

View File

@ -35,7 +35,7 @@ filter.format.*:
Length:
max: 255
weight:
type: integer
type: weight
label: 'Weight'
roles:
type: sequence

View File

@ -23,7 +23,7 @@ image.style.*:
manager: plugin.manager.image.effect
interface: 'Drupal\image\ImageEffectInterface'
weight:
type: integer
type: weight
data:
type: image.effect.[%parent.id]

View File

@ -98,7 +98,7 @@ language.entity.*:
type: string
label: 'Direction'
weight:
type: integer
type: weight
label: 'Weight'
locked:
type: boolean

View File

@ -51,7 +51,7 @@ layout_builder.component:
configuration:
type: block.settings.[id]
weight:
type: integer
type: weight
label: 'Weight'
additional:
type: ignore

View File

@ -81,7 +81,7 @@ search.page.*:
type: string
label: 'Search page path'
weight:
type: integer
type: weight
label: 'Weight'
plugin:
type: string

View File

@ -44,11 +44,8 @@ taxonomy.vocabulary.*:
NotBlank:
allowNull: true
weight:
type: integer
type: weight
label: 'Weight'
# A weight can be any integer, positive or negative.
constraints:
NotNull: []
new_revision:
type: boolean
label: 'Whether a new revision should be created by default'

View File

@ -49,7 +49,7 @@ tour.tip:
type: required_label
label: 'Label'
weight:
type: integer
type: weight
label: 'Weight'
position:
type: string

View File

@ -114,7 +114,7 @@ user.role.*:
type: required_label
label: 'Label'
weight:
type: integer
type: weight
label: 'User role weight'
is_admin:
type: boolean

View File

@ -32,7 +32,7 @@ views.display.page:
type: text
label: 'Description'
weight:
type: integer
type: weight
label: 'Weight'
enabled:
type: boolean
@ -63,7 +63,7 @@ views.display.page:
type: text
label: 'Description'
weight:
type: integer
type: weight
label: 'Weight'
menu_name:
type: string

View File

@ -26,7 +26,7 @@ workflows.state:
label: 'Label'
translation context: 'Workflow state label'
weight:
type: integer
type: weight
label: 'Weight'
workflows.transition:
@ -46,5 +46,5 @@ workflows.transition:
type: string
label: 'To state ID'
weight:
type: integer
type: weight
label: 'Weight'

View File

@ -157,7 +157,7 @@ class ConfigSchemaTest extends KernelTestBase {
];
$expected['mapping']['weight'] = [
'label' => 'Weight',
'type' => 'integer',
'type' => 'weight',
];
$expected['type'] = 'config_schema_test.ignore';
$expected['unwrap_for_canonical_representation'] = TRUE;
@ -206,7 +206,7 @@ class ConfigSchemaTest extends KernelTestBase {
],
];
$expected['mapping']['effects']['sequence']['mapping']['data']['type'] = 'image.effect.[%parent.id]';
$expected['mapping']['effects']['sequence']['mapping']['weight']['type'] = 'integer';
$expected['mapping']['effects']['sequence']['mapping']['weight']['type'] = 'weight';
$expected['mapping']['effects']['sequence']['mapping']['uuid']['type'] = 'uuid';
$expected['mapping']['third_party_settings']['type'] = 'sequence';
$expected['mapping']['third_party_settings']['label'] = 'Third party settings';

View File

@ -71,8 +71,11 @@ class ConfigEntityAdapterTest extends KernelTestBase {
]);
$adapter = ConfigEntityAdapter::createFromEntity($this->entity);
$violations = $adapter->validate();
$this->assertCount(1, $violations);
$this->assertCount(2, $violations);
$violation = $violations->get(0);
$this->assertEquals('This value should be a valid number.', $violation->getMessage());
$this->assertEquals('weight', $violation->getPropertyPath());
$violation = $violations->get(1);
$this->assertEquals('This value should be of the correct primitive type.', $violation->getMessage());
$this->assertEquals('weight', $violation->getPropertyPath());
}