- Issue created by @pdureau
- Issue was unassigned.
- Status changed to Needs review
4 months ago 7:52pm 27 August 2024 - π«π·France Grimreaper France π«π·
pdureau β credited grimreaper β .
- π«π·France pdureau Paris
Let's do the early alteration in ComponentPluginManager::annotateProps().
π [2.0.0-beta2] Expose default attributes prop in forms Closed: duplicate is now obsolete and can be closed
- Merge request !188Issue #3470231 by pdureau, grimreaper, g4mbini, smustgrave: Attributes normalization β (Merged) created by pdureau
- Assigned to pdureau
- Status changed to Needs work
4 months ago 1:54pm 29 August 2024 - π«π·France pdureau Paris
We have this PHP Unit error in the pipeline:
Drupal\Core\Render\Component\Exception\InvalidComponentException: [attributes] String value found, but an object is required
It may be related to π [2.0.0-beta2] Check PropTypeInterface::normalize() Active
- π«π·France just_like_good_vibes PARIS
pdureau β credited just_like_good_vibes β .
- π«π·France pdureau Paris
Checked with Mikael
It is SDC's ComponentValidator::validateProps() which is calling a dependency method which is executing json_encode() which is casting the attribute object into a string.
So, we may need 2 different methods:
- keep
PropTypeInterface::normalize()
before the ComponentValidator, which is always returning data conform to JSON Schema, so which is keeping the associative array for attributes - add a new method (
PropTypeInterface::preprocess()
?) in between the ComponentValidator and the injection to Twig template, which is instantiating the Attribute object
Unfortunately, ComponentValidator may be executed very late, from a Twig extension, so we may need to add our own Twig extension to be executed after.
- keep
- π«π·France pdureau Paris
SDC implementation looks a bit messy IMHO:
ComponentsTwigExtension is adding 2 twig functions:
add_component_context
which is adding the attribute Attribute object if missingvalidate_component_props
which is executing the JSON schema validator
Why are they Twig functions instead of living in the rendering process? Who will ever use them in the template? I don't know
Then, ComponentNodeVisitor is ever more problematic, because it prints those Twig functions on every template, which will be executed on rendering:
- attach_library
- add_component_context
- validate_component_props
And this is making all the mess. What we are paying here is the cost of the use of "template to template" Twig functions or tags (
include
andembed
) instead of a dedicated mechanism which is loading the Render API and leveraging the render element. For example,attach_library
is used here because#attached
is not executed.All this part of SDC would be to be removed and redone, but it will take time.
What can we do now, in this ticket, to overcome this?
- π«π·France pdureau Paris
DRAFT - WORK IN PROGRESS: WILL BE UPDATED WITH BETTER INFO
So, let's see every possible situation.
No attribute in template context
No attribute in JSON schema
add_component_context
is adding an Attribute objectvalidate_component_props
is skipping the validation, so it is OK β
Attribute as a namespaced PHP class in JSON schema
The same:
add_component_context
is adding an Attribute objectvalidate_component_props
is skipping the validation, so it is OK β
Attribute as a proper JSON schema definition (the UI Patterns 2.x way)
add_component_context
is adding an Attribute objectvalidate_component_props
is doing the validation, and it is supposed to be KO β
attribute
as a PHP object in template contextNo attribute in JSON schema
add_component_context
is altering the Attribute objectvalidate_component_props
is skipping the validation, so it is OK β
attribute
as a namespaced PHP class in JSON schemaThe same:
add_component_context
is altering the Attribute objectvalidate_component_props
is skipping the validation, so it is OK β
Attribute as a proper JSON schema definition (the UI Patterns 2.x way)
add_component_context
is doing nothingvalidate_component_props
is doing the validation, because a β
attribute
as a PHP array in template contextThis will be the situation if we remove
AttributePropType::normalize()
No attribute in JSON schema
add_component_context
is doing nothingvalidate_component_props
is skipping the validation, so it is OK β
Attribute as a namespaced PHP class in JSON schema
The same:
add_component_context
is doing nothingvalidate_component_props
is skipping the validation, so it is OK β
Attribute as a proper JSON schema definition (the UI Patterns 2.x way)
add_component_context
is doing nothingvalidate_component_props
is doing the validation, and it i supposed to be KO because a β
- Issue was unassigned.
- Status changed to Needs review
3 months ago 4:16pm 6 September 2024 -
just_like_good_vibes β
committed 0f9e8a8e on 2.0.x authored by
pdureau β
Issue #3470231 by pdureau, just_like_good_vibes, g4mbini, grimreaper,...
-
just_like_good_vibes β
committed 0f9e8a8e on 2.0.x authored by
pdureau β
- Status changed to Fixed
3 months ago 1:58pm 9 September 2024 - Status changed to Fixed
3 months ago 7:26pm 15 September 2024