Problem/Motivation
With table component in USB, I have the following errors:
Drupal\Core\Render\Component\Exception\InvalidComponentException: [borders] NULL value found, but a string or an object is required. This may be because the property is empty instead of having data present. If possible fix the source data, use the |default() twig filter, or update the schema to allow multiple types./n[borders] Does not have a value in the enumeration ["bordered","borderless"]/n[responsive] NULL value found, but a string or an object is required. This may be because the property is empty instead of having data present. If possible fix the source data, use the |default() twig filter, or update the schema to allow multiple types./n[responsive] Does not have a value in the enumeration ["responsive","responsive-sm","responsive-md","responsive-lg","responsive-xl","responsive-xxl"] in Drupal\Core\Theme\Component\ComponentValidator->validateProps() (line 203 of core/lib/Drupal/Core/Theme/Component/ComponentValidator.php).
Note that I started to put a default value in header_color and footer_color props but I had the same problem.
Proposed resolution
It should be possible to inject an empty string or NULL value for presenter templates and not get an error.
Remaining tasks
Find a generic solution.
Issue fork ui_patterns-3491369
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
pdureau commentedComment #3
just_like_good_vibesthis was supposed to be properly handled in enum prop normalisation :)
i guess it may not be totally the cass
Comment #4
pdureau commentedCan you take it Mikael?
Comment #5
just_like_good_vibesof course i will post the code :)
Comment #6
just_like_good_vibesComment #7
just_like_good_vibesComment #9
just_like_good_vibesi don't remember if it makes sense to indicate a default value in the json schema definition of a prop?
by the way, the enum prop type normalization is giving a try to get the default enum value from the "default" when no value was selected.
in the case which is submitted here, i just checked, and borders indicate no default.
i have updated the code, with many bonus, including the management of minItems and maxItems, in the case of EnumList and EnumSet.
please review
Comment #10
just_like_good_vibessome tests are failing, i will correct that
Comment #11
grimreaperHi,
Thanks, it fixes the fatal error.
But I have "Warning: Array to string conversion in Drupal\ui_patterns\Plugin\UiPatterns\PropType\EnumPropType::convertValueToEnumType() (line 55 of modules/contrib/ui_patterns/src/EnumTrait.php)."
Comment #12
just_like_good_vibeshum your warning, is strange, can i reproduce?
it means an array has been passed to the
convertValueToEnumTypewhich means two options :
- there is a little bug somewhere, an array is passed to the function but it should not. we could correct or add an additional check
- you have a little bug somewhere, you inject an array in an enum value
Comment #13
walli commentedHello ,
I applied the patch but this warning , is still displaying
Warning: Array to string conversion in Drupal\ui_patterns\Plugin\UiPatterns\PropType\EnumPropType::convertValueToEnumType() (line 55 of modules/contrib/ui_patterns/src/EnumTrait.php)
Comment #14
just_like_good_vibesHello, has someone a stacktrace please. it will help me accelerate the fix :)
Comment #15
grimreaperGo on /filter/tips with UI Suite Bootstrap.
4 times this message:
Maybe at this moment it is a presenter template problem.
Comment #16
walli commented.
Comment #17
just_like_good_vibesthanks.
I wonder if, the prop is a simple enum, but the value injected is an array...
on that case :
- is the prop supposed to be a list of enum?
OR
- is the value supposed to scalar instead of a table
Comment #18
just_like_good_vibesi just added a new test to avoid the warning, but it won't solve your problem of an array being injected instead of a scalar..
Comment #19
pdureau commentedIndeed, EnumPropType is a scalar prop type.
Comment #20
just_like_good_vibesready for review (and merge :) )
Comment #22
pdureau commentedComment #23
grimreaperHi,
Don't know if related but now I have:
When on the components library
Edit: it seems not related and due to #3491238: [2.0.0-beta6] normalization of slots triggers some unwanted filtering
Comment #25
grimreaperBug aside.
I don't think getting the first enum value is a solution.
I want the prop to remain optional, so without value.
Comment #27
just_like_good_vibes"I want the prop to remain optional, so without value."
for this, it is a bit more tricky to do.
if you prop is of type "string", and you don't declare any "default",
and you still want an empty string as default :) ?
is empty string a possible enum value ?
and also i would rather put empty string as default...
because sometimes enum could have different types, mixed types..etc
i am curious about what Pierre thinks about that. maybe i am completly wrong in my approach.
Comment #28
grimreaperEmpty string is ok in the case of a string type, I have discussed with Pierre about that yesterday or tuesday.
We just don't want to have to declare an empty enum value at each enum.
But like you said let's wait to get Pierre's feedback.
Comment #29
grimreaperComment #30
grimreaperComment #31
just_like_good_vibesyes we need to figure out the options.
First, how things are declared using SDC, in json schema
- type
- required
- default
The current code in
normalizeis trying to get the "default", like this :We are discussing the possibilities of changing the enumDefaultValue returned.
when there is not "default" declared in json schema, and when the type is explicitely defined (and would be further checked by SDC)
we indeed return the first enum value.
Perhaps we could refine this :
- if required is defined and true in the definition, we returned the first enum value (and not empty string)
- otherwise : depending on the type, we try to return a default 'empty' value .
-- type can be an array or a scalar if i am not wrong. when string is a compatible type, we return empty string,
-- otherwise, what do we return ? first enum value?
one again, we are in an edge case, where :
- the definition has not indicated a default value,
- the value passed is not part of the enum declared
- the enum is explicitely typed and the value will be validated.
- we try to guess a default valid value to avoid a failed validation, and the first enum is not good.
in the case of enum of type string, when declared without required, one would expect that it means optional with default value being empty string.
Comment #33
just_like_good_vibesI just submitted the new proposition.
When no default value is defined for an enum :
- if enum has type compatible with string, and if not required, the default value is now empty string
- otherwise default value is first enum value
Comment #35
pdureau commentedComment #36
pdureau commentedComment #37
pdureau commented