we should probably make these special strings constants

const DYNAMIC_SOURCE_TYPE = 'dynamic';
const STATIC_SOURCE_TYPE_PREFIX = 'static:';

https://git.drupalcode.org/project/experience_builder/-/merge_requests/2... @larowlan review for #3452497: [MR Only] Edit any component prop, powered by a new FieldForComponentSuggester service, which will power the JS UI.

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

Wim Leers created an issue. See original summary.

wim leers’s picture

Title: [PP-1] 3450586 » [PP-1] Centralize & standardize logic for constructing *PropSource objects

wim leers’s picture

Assigned: wim leers » larowlan
Status: Postponed » Needs review
Issue tags: +API clean-up

Blocked on #3452497: [MR Only] Edit any component prop, powered by a new FieldForComponentSuggester service, which will power the JS UI landing first, but @larowlan can already review this — just only review the last commit 🙏

wim leers’s picture

Title: [PP-1] Centralize & standardize logic for constructing *PropSource objects » Centralize & standardize logic for constructing *PropSource objects
lauriii’s picture

Assigned: larowlan » Unassigned
Status: Needs review » Needs work

The MR pipeline is failing.

tedbow made their first commit to this issue’s fork.

tedbow’s picture

Status: Needs work » Needs review

Pipeline is passing

wim leers’s picture

@larowlan or @tedbow, could you review? 🙏

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

@larowlan Thanks! Merging in all upstream commits first…

Only developers would maybe see the string representation of (Static|Dynamic)PropSources. And they definitely won't be reading that representation in JSON-encoded-in-YAML form (although there we could do the work to not use \u<unicode code point> but just use the Unicode representation directly — we should do that, it's just not urgent, especially if we don't know we'll continue to use this approach).

This is a data structure ((Static|Dynamic|Adapted)PropSource are strongly typed PHP objects), it's just one that has an equivalent string representation. That string representation allows both for a more compact representation, resulting in less (cognitive & space) overhead when looking at an entire component tree. I wanted a string representation
because that makes searching (googling/ducking) for problems much simpler.

I respectfully disagree with you that only a data structure, without a string representation, would be better. You'd then at minimum still need an array representation to be able to express/store it in JSON/YAML, and I wanted to avoid a new Type Of Array of Doom 😅 — but it sounds like you think this is perhaps the first Type of String of Doom? 😅

All that being said: this seemed the best/simplest path to something that works that I could see. If you feel so strongly that there is a better way, then I'm absolutely open to an alternative. Whether you provide that in the form of a photo of drawings on a napkin, sample JSON blobs or an MR, is your choice :)

wim leers’s picture

Assuming that the \u<unicode code point> aspect was a significant part of what @larowlan was referring to in his MR comment, that's easily solved by using https://www.php.net/manual/en/function.json-encode.php.

Note that \Drupal\experience_builder\PropSource\StaticPropSource::__toString() already uses that … it's just that https://git.drupalcode.org/project/experience_builder/-/blame/0.x/config... was handcrafted and does not yet have validation constraints that would detect/prevent this particular encoding. Fixed with a simple print json_encode(json_decode($s), JSON_UNESCAPED_UNICODE);: https://git.drupalcode.org/project/experience_builder/-/merge_requests/4... :)

wim leers’s picture

Add test coverage to A) reduce the concerns voiced by @larowlan, B) empower him/others to propose an alternative implementation. The test shows the range of needed capabilities — EndToEndDemoIntegrationTest already did that, but the new PropSourceTest does so in more detail, and in a kernel instead of functional test: https://git.drupalcode.org/project/experience_builder/-/merge_requests/4...

wim leers’s picture

Title: Centralize & standardize logic for constructing *PropSource objects » Centralize & standardize logic for constructing *PropSource objects + kernel test coverage

  • Wim Leers committed 8c6d5ab5 on 0.x
    Issue #3453152 by Wim Leers, tedbow, larowlan: Centralize...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

@larowlan wrote I'm ok with the work in this branch. but did not click "approve" — so bypassed the explicit approval 🦹

larowlan’s picture

Re #11 @wim - my driver is making sure we don't repeat mistakes like https://dbushell.com/2024/05/07/modern-wordpress-themes-yikes/

In last week's meeting longwave voiced similar concerns about this and asked if JSON path was considered as a non dtupalism approach

wim leers’s picture

😄 I sent that exact link to @lauriii last week, voicing the exact same concern!

Status: Fixed » Closed (fixed)

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