Loading core/lib/Drupal/Core/Config/Plugin/Validation/Constraint/LangcodeRequiredIfTranslatableValuesConstraintValidator.php +6 −2 Original line number Diff line number Diff line Loading @@ -22,8 +22,12 @@ public function validate(mixed $value, Constraint $constraint): void { $mapping = $this->context->getObject(); assert($mapping instanceof Mapping); if ($mapping !== $this->context->getRoot()) { throw new LogicException('The LangcodeRequiredIfTranslatableValues constraint can only operate on the root object being validated.'); $root = $this->context->getRoot(); if ($mapping !== $root) { throw new LogicException(sprintf( 'The LangcodeRequiredIfTranslatableValues constraint is applied to \'%s\'. This constraint can only operate on the root object being validated.', $root->getName() . '::' . $mapping->getName() )); } assert(in_array('langcode', $mapping->getValidKeys(), TRUE)); Loading core/modules/config/tests/config_test/config/schema/config_test.schema.yml +7 −0 Original line number Diff line number Diff line Loading @@ -241,6 +241,13 @@ config_test.foo: label: type: label label: 'Label' # Note that config_object should never be used on a non-root key. broken_langcode_required: type: config_object required: false mapping: foo: type: string config_test.bar: type: config_test.foo Loading core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php +11 −0 Original line number Diff line number Diff line Loading @@ -848,4 +848,15 @@ public function testConfigSaveWithWrappingSchemaDoubleBrackets(): void { ], $definition['mapping']['breed']); } public function testLangcodeRequiredIfTranslatableValuesConstraintError(): void { $config = \Drupal::configFactory()->getEditable('config_test.foo'); $this->expectException(\LogicException::class); $this->expectExceptionMessage('The LangcodeRequiredIfTranslatableValues constraint is applied to \'config_test.foo::broken_langcode_required\'. This constraint can only operate on the root object being validated.'); $config ->set('broken_langcode_required.foo', 'bar') ->save(); } } Loading
core/lib/Drupal/Core/Config/Plugin/Validation/Constraint/LangcodeRequiredIfTranslatableValuesConstraintValidator.php +6 −2 Original line number Diff line number Diff line Loading @@ -22,8 +22,12 @@ public function validate(mixed $value, Constraint $constraint): void { $mapping = $this->context->getObject(); assert($mapping instanceof Mapping); if ($mapping !== $this->context->getRoot()) { throw new LogicException('The LangcodeRequiredIfTranslatableValues constraint can only operate on the root object being validated.'); $root = $this->context->getRoot(); if ($mapping !== $root) { throw new LogicException(sprintf( 'The LangcodeRequiredIfTranslatableValues constraint is applied to \'%s\'. This constraint can only operate on the root object being validated.', $root->getName() . '::' . $mapping->getName() )); } assert(in_array('langcode', $mapping->getValidKeys(), TRUE)); Loading
core/modules/config/tests/config_test/config/schema/config_test.schema.yml +7 −0 Original line number Diff line number Diff line Loading @@ -241,6 +241,13 @@ config_test.foo: label: type: label label: 'Label' # Note that config_object should never be used on a non-root key. broken_langcode_required: type: config_object required: false mapping: foo: type: string config_test.bar: type: config_test.foo Loading
core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php +11 −0 Original line number Diff line number Diff line Loading @@ -848,4 +848,15 @@ public function testConfigSaveWithWrappingSchemaDoubleBrackets(): void { ], $definition['mapping']['breed']); } public function testLangcodeRequiredIfTranslatableValuesConstraintError(): void { $config = \Drupal::configFactory()->getEditable('config_test.foo'); $this->expectException(\LogicException::class); $this->expectExceptionMessage('The LangcodeRequiredIfTranslatableValues constraint is applied to \'config_test.foo::broken_langcode_required\'. This constraint can only operate on the root object being validated.'); $config ->set('broken_langcode_required.foo', 'bar') ->save(); } }