Problem/Motivation

Following #3469808: [2.0.0-beta5] Use decorator instead overwriting the component plugin service we can now test UI Patterns 2 with Experience Builder (XB). Careful: in Decmeber 2024, XB is still in early dev and very unstable, so the results may change from day to day.

Using XB components in UIP2

XB's json-schema-definitions stream wrapper is not triggered by UI Patterns 2. Normally, it must be done automatically by the JSON Schema library, without any actions on our side, but let's check.

sounds crazy, but XB is also providing some SDC components, but most of them are not using the attributes variable in templates. Unfortunately, there is nothing to do on out side.

Using UIP2 components in WB

Let's investigate this error:
ValueError: "" is not a valid backing value for enum Drupal\experience_builder\JsonSchemaInterpreter\SdcPropJsonSchemaType in Drupal\experience_builder\JsonSchemaInterpreter\SdcPropJsonSchemaType::from() (line 131 of /src/PropShape/PropShape.php).

It happens when we use $ref: ui-patterns:// so also related to stream wrapper.

Let's check if both can be used, in which order they are called for reference resolution to see which one is breaking the other

Command icon 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

pdureau created an issue. See original summary.

pdureau’s picture

Issue summary: View changes
just_like_good_vibes’s picture

Assigned: Unassigned » just_like_good_vibes
just_like_good_vibes’s picture

i just gave a test with a fresh 11.1.0 drupal and the last experience_builder from dev branch.

i did not receive the mentioned errors.
i managed to check the UI and almost nothing worked. My components were appearing but they are still in such an early stage, it seems difficult to check anything yet.

pdureau’s picture

Assigned: just_like_good_vibes » pdureau
Status: Active » Needs work

No error? That s'great news. I will check again.

By the way, I know they are still very early stage, and I don't expect the builder to work properly, I just want the 2 JSON schema resolvers ($ref: ui-patterns:// and $ref: json-schema-definitions://) to work well together.

pdureau’s picture

Assigned: pdureau » Unassigned

No, it doesn't work.

Using XB components in UIP2

  • I install both ui_patterns_library and experience_builder
  • I got to /admin/appearance/ui/components/experience_builder/shoe_button
  • icon prop has this unknown prop type: {"$ref":"json-schema-definitions:\/\/experience_builder.module\/shoe-icon","type":"object"}

According to https://git.drupalcode.org/project/experience_builder/-/blob/0.x/schema.... the expected resolved json schema must be

title: Icon
type: object
properties:
  name:
    type: string
    title: Name
    default: primary
    enum:
    - moon-stars-fill
    - moon-stars
    - star-fill
    - star
    - stars
    - rocket-fill
    - rocket-takeoff-fill
    - rocket-takeoff
    - rocket

Which will be loaded as Enum prop by UIP2.

So, what is happening? Why the JSON schema reference is not resolved?

  • It is broken on Experience Builder side?
  • Is it broken because of having XB & UIP2 together?

Using UIP2 components in WB

I was not able to test because XB is currently broken:

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "experience_builder.experience_builder" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 211 of core/lib/Drupal/Core/Routing/RouteProvider.php).

Let's try later.

pdureau’s picture

Assigned: Unassigned » christian.wiedemann

christian.wiedemann made their first commit to this issue’s fork.

pdureau’s picture

Using XB components in UIP2

The issue was on UIP2 side. Fixed by Christian in https://git.drupalcode.org/issue/ui_patterns-3490873/-/commit/51c4ea3e22...

But he needs to add some tests.

Using UIP2 components in WB

We are not able to test because XB is currently broken (not the same bug as yesterday...). Let's wait a bit and pull again.

pdureau’s picture

pdureau’s picture

Today, we decided to merge this issue because the Using XB components in UIP2 fix is enough for RC1 (after adding some tests, right?).

About Using UIP2 components in XB:

  • It seems XB is not resvolving $ref: ui-patterns:// but it may not resolved "$ref":"json-schema-definitions: either, so let's wait they implement a working reference resolver
  • when both XB and UIP2 are installed, XB is raising errors, so our component plugin manager decorators may not be fully compatible
  • XB is not loading UIP2 components (!) but is loading the ui_patterns_blocks's blocks twice, because of our (UIP2) context management; we derivate blocks twice, one with entity context and one without

Let's create a 2.1.0 issue.

christian.wiedemann’s picture

Assigned: christian.wiedemann » pdureau
Status: Needs work » Needs review

This ticket takes way too long. The problem behind the phpunit error was that we don't validate the scheme correctly because we imported the refs after the validation. enum_list returns false empty values which leads than to the error. So I fixed the empty value handling of enum_list. I also try to test validation with schema.json like expierence_builder does. The problem here is that xb uses its own stream wrapper. All my tests with refs with local files doesn't work and I also could not find any solution to handle this. So i removed the the test again.

pdureau’s picture

Assigned: pdureau » christian.wiedemann
Status: Needs review » Needs work
    $values = array_filter($values, fn($value) => !is_null($value) && $value !== '');

Why are you removing the empty values? They can be legit in some enumerations. Is removing only the null values enough?

christian.wiedemann’s picture

We need to remove empty strings if they are not part of the enum list. Propably we should remove all values which are not part of the enum list. Removing a entry from the enum list would lead to an exception which will be hard to fix for sitebuilders because the page crashes before. So I would suggest removing values which are not part of the enum list.

christian.wiedemann’s picture

christian.wiedemann’s picture

Propably the bug occurst because EnumTrait::normalizeEnumListSize is not triggerd before. I will investigate that.

christian.wiedemann’s picture

pdureau’s picture

We need to remove empty strings if they are not part of the enum list. Propably we should remove all values which are not part of the enum list

It is nice to do it in the source plugin, but the prop type plugin have a ::normalization() method.

christian.wiedemann’s picture

Okay I checked it again. We need to load non ui-patterns references first and after that we load ui patterns references. So actual problem was a wrong schema guessing if we load all references and than we do prop type guessing only on schema (without $ref="ui-patterns://").
So I split the ref loading in two steps. This should work. But we can also wait for rc2 with this fix. Not sure if "ref" is often used in SDC right now without custom stream wrappers like xb is doing.

christian.wiedemann’s picture

Assigned: christian.wiedemann » pdureau
Status: Needs work » Needs review
pdureau’s picture

Not sure if "ref" is often used in SDC right now without custom stream wrappers like xb is doing.

There are 2 ways of using the JSON Schema $ref system AFAIK:

  • With a custom stream wrapper like we do in UI Patterns 2 (ui-patterns:// with StreamWrapper) and Experience Builder (json-schema-definitions:// with JsonSchemaDefinitionsStreamwrapper)
  • With simple URI retrieval when the URI is dereferencable: http(s), file, ftp...

pdureau’s picture

Assigned: pdureau » Unassigned
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

christian.wiedemann’s picture