- Issue created by @Niklan
- Status changed to Needs review
about 2 months ago 5:15pm 17 July 2024 - π·πΊRussia Niklan Russia, Perm
Added the test that will fail with such definition. It is practically useless, I think, but it shows that the input and expected data are not the same. If you try to render it, a PHP error occurs. Maybe we should throw an exception in that case, I don't know.
- π·πΊRussia Niklan Russia, Perm
I propose to throw an exception if the types of the property contain values that are not strings, which will include floats and special YAML types. We definitely do not want to correct the value
!!float 12.3
in any way. We should throw a meaningful exception, indicating the component ID and property name. Then developers can easily identify and fix the problem.If we are going to fix
NULL
for developers automatically, we still have to check for other types and throw an exception. So it's just more code with basically the same result. - π·πΊRussia Niklan Russia, Perm
Added check for property type definition values, and if it contains a non-string value, throws an exception. In my case, it is now clear where the problem is:
Drupal\Core\Render\Component\Exception\InvalidComponentException: The component "foo:bar" uses non-string types for properties: required. in Drupal\Core\Theme\Component\ComponentValidator->validateDefinition() (line 96 of core/lib/Drupal/Core/Theme/Component/ComponentValidator.php).
$schema: https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json name: Bar props: type: object properties: required: type: [null, boolean] title: Required
- Status changed to RTBC
30 days ago 2:13pm 9 August 2024 - πΊπΈUnited States smustgrave
Tried to get some feedback in the slack channel #components but no luck.
Believe this is a net improvement for sure though
Test-only feature shows that
1) Drupal\Tests\Core\Theme\Component\ComponentValidatorTest::testValidateDefinitionInvalid with data set #3 (['https://git.drupalcode.org/pr...a.json', 'Call to Action', 'My description', ['object', ['text'], [[null, 'Title', 'The title for the cta', ['Press', 'Submit now']], ['string', 'URL', 'uri'], ['string', 'Target', ['', '_blank']], ['Drupal\Core\Template\Attribute', 'Attributes']]], 'my-cta', 'module', 'sdc_test:my-cta', [[[[]]]], '', 'sdc_test', 'my-cta.twig', 'my-group']) Failed asserting that exception of type "Drupal\Core\Render\Component\Exception\InvalidComponentException" is thrown. 2) Drupal\Tests\Core\Theme\Component\ComponentValidatorTest::testValidateDefinitionInvalid with data set #4 (['https://git.drupalcode.org/pr...a.json', 'Call to Action', 'My description', ['object', ['text'], [[['string', null], 'Title', 'The title for the cta', ['Press', 'Submit now']], ['string', 'URL', 'uri'], ['string', 'Target', ['', '_blank']], ['Drupal\Core\Template\Attribute', 'Attributes']]], 'my-cta', 'module', 'sdc_test:my-cta', [[[[]]]], '', 'sdc_test', 'my-cta.twig', 'my-group']) Failed asserting that exception of type "TypeError" matches expected exception "Drupal\Core\Render\Component\Exception\InvalidComponentException". Message was: "Drupal\Core\Theme\Component\ComponentValidator::Drupal\Core\Theme\Component\{closure}(): Argument #1 ($type) must be of type string, null given" at /builds/issue/drupal-3462156/core/lib/Drupal/Core/Theme/Component/ComponentValidator.php:278 /builds/issue/drupal-3462156/core/lib/Drupal/Core/Theme/Component/ComponentValidator.php:84 /builds/issue/drupal-3462156/core/tests/Drupal/Tests/Core/Theme/Component/ComponentValidatorTest.php:62
- Status changed to Needs work
24 days ago 2:24am 15 August 2024 - π³πΏNew Zealand quietone New Zealand
I don't see that anyone has received the code for this issue, only that the test only feature has been used. Remember, issues do need a code review. I thought at first that this was throwing a new exception but I see that it is not. I do think a comment is needed, which I indicated in the MR, perhaps some of the detail in #4 would be useful there.
The title here should include some indication of what this fix applies to. The title should be a description of what is being fixed or improved. The title is used as the git commit message so it should be meaningful an concise. See List of issue fields β .
So, two small things, although this still needs a review by someone familiar with this component.
- Status changed to Needs review
24 days ago 2:52pm 15 August 2024 - Status changed to RTBC
23 days ago 1:56pm 16 August 2024 - πΊπΈUnited States smustgrave
Believe title reflects the change so removing that tag.
Also appears additional feedback has been addressed
- π§πͺBelgium Wim Leers Ghent π§πͺπͺπΊ
I think the test could be slightly clearer (see MR comment), but I think this is ready nonetheless π