- Issue created by @lauriii
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
This is incomplete because it still allows
type: object
with arbitrary other values to be specified. IOW: more validation logic is needed.But โฆ this should allow the FE work to begin right now:
diff --git a/config/schema/experience_builder.schema.yml b/config/schema/experience_builder.schema.yml index b3c76f77..8f86dd25 100644 --- a/config/schema/experience_builder.schema.yml +++ b/config/schema/experience_builder.schema.yml @@ -102,9 +102,20 @@ experience_builder.js_component.*: - 'number' - 'integer' - 'boolean' - # @todo Consider adding `array` after https://www.drupal.org/i/3467870 is fixed. - # @todo Consider adding `object`, but defining _arbitrary_ object shapes is not yet supported. + # โ ๏ธ Defining _arbitrary_ object shapes is not yet supported. Currently only one such shape is + # supported: images, which requires `type: object` plus + # `$ref: json-schema-definitions://experience_builder.module/image`. # @see \Drupal\experience_builder\JsonSchemaInterpreter\SdcPropJsonSchemaType::computeStorablePropShape() + - 'object' + # @todo Consider adding `array` after https://www.drupal.org/i/3467870 is fixed. + '$ref': + requiredKey: false + type: string + constraints: + # All choices listed here must be supported: they must have a corresponding storable prop shape. + # @see \Drupal\experience_builder\JsonSchemaInterpreter\SdcPropJsonSchemaType::computeStorablePropShape() + Choice: + - 'json-schema-definitions://experience_builder.module/image' description: requiredKey: false type: label
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
( โจ Config entity for storing code components Active heavily restricted what props you're allowed to use.)
- ๐ซ๐ฎFinland lauriii Finland
Cross referencing an issue to add support for textarea in the code editor which is likely very similar to this.
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
That's right: #3507928-2: Allow adding textarea in the code editor โ .
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
What's not yet explained in #2, is the explicit validation.
We'll need to add a new validation constraint:
diff --git a/config/schema/experience_builder.schema.yml b/config/schema/experience_builder.schema.yml index e3352d5b..26e26d27 100644 --- a/config/schema/experience_builder.schema.yml +++ b/config/schema/experience_builder.schema.yml @@ -96,6 +96,8 @@ experience_builder.js_component.*: type: sequence sequence: type: mapping + constraints: + IsStorablePropShape: ~ mapping: title: type: required_label
This then receives every key-value pair under
props
, so something like$value = [ 'type' => 'string', 'title' => 'Title', 'examples' => ['Press', 'Submit now'], ];
(this is the example in
\Drupal\Tests\experience_builder\Kernel\Config\JavaScriptComponentValidationTest::setUp()
).The validation constraint's validator then should do something like:
class IsStorablePropShapeConstraintValidator extends ConstraintValidator { /** * {@inheritdoc} */ public function validate(mixed $value, Constraint $constraint): void { if (!is_array($value)) { // If the value is NULL, then the `NotNull` constraint validator will // set the appropriate validation error message. // @see \Drupal\Core\Validation\Plugin\Validation\Constraint\NotNullConstraintValidator if ($value === NULL) { return; } throw new UnexpectedTypeException($value, 'array'); } // Verify an absolute minimum of an JSON Schema definition is present. If // not, do not perform further validation; it's up to the other validation // constraints to consider this overall value invalid. // @todo Ideally, we'd only validate this if and only if all key-value pairs in this mapping entry are valid. That requires conditional/sequential execution of validation constraints, which Drupal does not currently support. // @see https://www.drupal.org/project/drupal/issues/2820364 if (!array_key_exists('type', $value)) { return; } if (PropShape::normalize($value)->getStorage() == NULL) { $this->context->buildViolation($constraint->message) // @todo look at \Drupal\Core\Validation\Plugin\Validation\Constraint\ValidKeysConstraintValidator for how to surface the key ("prop name") for which this occurred so you can include it in the error message โฆ ->addViolation(); } } }
Look at
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
Needs explicit test coverage, probably just a new case in
\Drupal\Tests\experience_builder\Kernel\Config\JavaScriptComponentValidationTest::providerTestEntityShapes()
?Blocks #3507928, see #3507928-3: Allow adding textarea in the code editor โ .
Once the BE MR is in
- ๐ฌ๐งUnited Kingdom f.mazeikis Brighton
f.mazeikis โ made their first commit to this issueโs fork.
- Merge request !700Add object schema and storable prop validation โ (Merged) created by Unnamed author
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
Tests are present ๐ CI results look promising. MR looks great, only nits! ๐
- ๐ฌ๐งUnited Kingdom f.mazeikis Brighton
Addressed nits, updated one failing test, waiting on CI.
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
Just one last suggestion on the MR, but this is good to go!
- ๐ฌ๐งUnited Kingdom f.mazeikis Brighton
Implemented the last suggestion, addressed failing CI on ESlint and merged.
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
Now ready for the front-end part!
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
@f.mazeikis We forgot to update
openapi.yml
and expand\Drupal\Tests\experience_builder\Functional\XbConfigEntityHttpApiTest::testJavaScriptComponent()
to test either what this MR landed, or what โจ Allow adding textarea in the code editor Active 's back-end MR landed.I vote explicitly testing
type: object, $ref: json-schema-definitions://experience_builder.module/image
in the internal HTTP API integration test. - ๐บ๐ธUnited States tedbow Ithaca, NY, USA
wim leers โ credited tedbow โ .
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
Looks like the
components.schemas.CodeComponent
inopenapi.yml
is not very precise currently (and it can't be due to ๐ CI: temporary intervention to avoid response latency-sensitive E2E tests from failing Active ) and thanks to that, it looks like this wouldn't fail tests.P.S.: it's thanks to @tedbow's work on ๐ Javascript code components props, examples and description should be optional Active that I even realized #19, so crediting him for that ๐
- First commit to issue fork.
- Merge request !730#3507929: Frontend for "Image" props in code components โ (Merged) created by Unnamed author
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
@balintbrews was hitting
AssertionError: assert($componentSource instanceof UrlRewriteInterface) in assert()
Analyzed it. Conclusion:
$default_resolved_value
is computed correctly, and is set to the absolute image URL that was specified as the default- โฆ but
::getClientSideInfo()
doesnโt yet pass that to the client, thatโs up to ๐ Split model values into resolved and raw Active to do! ๐ฌ - so the client cannot send the resolved value to the server, because it simply doesnโt exist on the client
- โฆ which then hits the
UrlPreviewPropSource
fallback case inGeneratedFieldExplicitInputUxComponentSourceBase::clientModelToInput()
โฆ but that is designed to only be created when thereโs a need for actual rewriting - Iโll work around it by implementing adding a no-op
JsComponent::rewriteExampleUrl()
with a @todo pointing to #3493943
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
Done. This is the very first code component containing an image ever rendered โ forgive the ugliness of my test content ๐คฃ
I'll let @balintbrews record a magnificent screencast instead ๐๐
P.S.: all of this is only possible thanks to the work @longwave and I did on ๐ Adding the Image component results in a state considered invalid Active ๐ฅณ
P.P.S.: @longwave +1'd #25's approach โ crediting him. -
wim leers โ
committed a80ea149 on 0.x authored by
balintbrews โ
Issue #3507929 by f.mazeikis, balintbrews, wim leers, tedbow, longwave,...
-
wim leers โ
committed a80ea149 on 0.x authored by
balintbrews โ
Automatically closed - issue fixed for 2 weeks with no activity.