- Issue created by @prudloff
- π«π·France prudloff Lille
The MR adds support for the first level of array items, but it would probably be best to implement this recursively.
- last update
over 1 year ago Custom Commands Failed - @prudloff opened merge request.
- πͺπΈSpain vidorado Pamplona (Navarra)
@geek-merlin was there and checked that it worked, but only for first level property types. For property items type, it doesn't work yet. I've applied the changes in MR4871 but it still doesn't work for me.
@prudloff, Could you review again your changes against the latest Drupal core (10.2.6 at the moment) to check if anything has changed in ComponentValidator::nullifyClassPropsSchema() that makes your changes don't work?
While I was fighting with it by myself, I changed the method ComponentValidator::getClassProps() to retrieve also the classes of item types. There is, maybe it could help.
$types = is_string($type) ? [$type] : $type;
changed to
if (is_array($type) && in_array('array', $type) && ($itemsType = $prop_def['items']['type'] ?? NULL)) { $types = is_string($itemsType) ? [$itemsType] : $itemsType; } else { $types = is_string($type) ? [$type] : $type; }
but that doesn't make it work either.
The code in this Validator is very hard for me to understand, it has a very strong array manipulation with reducers and the like...
- πͺπΈSpain vidorado Pamplona (Navarra)
For anyone also on this issue... I would like to share my experience after some playing with it :)
I realized that working with classes in SDC property definitions is not as practical as I first thought. The magic of SDC is in creating components "on the fly" in yor theme's twig files, and that is not possible if you have to provide a Class argument to a component.
If we would have a way of creating class objects from plain objects or arrays directly from twig (with a function, filter, whatever...) this could all be possible but, without that, I think is better to go along with simple types (string, boolean, integer...) and enums. We will have a little bit of repetition if we, for example, use the same enum in several places, but it is manageable.
If, like me, you also are lacking autocompletion when defining component properties, maybe a plugin for PHPStorm/VSCode could be developed, that was aware of SDC definitions.