Skip to content
Snippets Groups Projects
Verified Commit d8dc9aa1 authored by Alex Pott's avatar Alex Pott
Browse files

Improve deprecation message

parent d80d3f8a
No related branches found
No related tags found
No related merge requests found
......@@ -21,9 +21,12 @@ public function validate(mixed $value, Constraint $constraint): void {
$mapping = $this->context->getObject();
assert($mapping instanceof Mapping);
if ($mapping !== $this->context->getRoot()) {
// @todo Convert this deprecation to LogicException.
@trigger_error('Calling the LangcodeRequiredIfTranslatableValues constraint on other than the root object being validated is deprecated in drupal:10.3.0 and removed in drupal:11.0.0. See https://www.drupal.org/project/drupal/issues/3449851', E_USER_DEPRECATED);
$root = $this->context->getRoot();
if ($mapping !== $root) {
@trigger_error(sprintf(
'The LangcodeRequiredIfTranslatableValues constraint can only be applied to the root object being validated, using the \'config_object\' schema type on \'%s\' is deprecated in drupal:10.3.0 and will trigger a \LogicException in drupal:11.0.0. See https://www.drupal.org/node/3459863',
$root->getName() . '::' . $mapping->getName()
), E_USER_DEPRECATED);
return;
}
......
......@@ -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
......
......@@ -854,4 +854,21 @@ public function testConfigSaveWithWrappingSchemaDoubleBrackets(): void {
], $definition['mapping']['breed']);
}
/**
* @group legacy
*/
public function testLangcodeRequiredIfTranslatableValuesConstraintError(): void {
$config = \Drupal::configFactory()->getEditable('config_test.foo');
$config
->set('broken_langcode_required.foo', 'bar')
->save();
$this->expectDeprecation('The LangcodeRequiredIfTranslatableValues constraint can only be applied to the root object being validated, using the \'config_object\' schema type on \'config_test.foo::broken_langcode_required\' is deprecated in drupal:10.3.0 and will trigger a \LogicException in drupal:11.0.0. See https://www.drupal.org/node/3459863');
$violations = \Drupal::service('config.typed')->createFromNameAndData($config->getName(), $config->get())
->validate();
$this->assertCount(0, $violations);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment