While attempting to find a solution in Drupal Commerce issue #2915559: Display custom fields on order admin view page, I discovered that Commerce Orders do not support the Layout Builder module because the StateTransitionFormFormatter cannot properly build a preview (resulting in a fatal error). Upon further investigation this is because the StateItem field type does not implement a generateSampleValue() method.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 3137212-13.patch | 5.1 KB | jsacksick |
Comments
Comment #2
neograph734First attempt to return a sensible value.
Comment #4
neograph734Missed the use statements...
Comment #5
neograph734Adding this is a child issue of Commerce #2952529: Support for Layout Builder module.
Comment #6
neograph734Comment #7
jsacksick commentedThe code is very ugly :p, especially the recursion part...
Maybe we could getaway with simply calling the
create()on the storage instead ofcreateWithSampleValues()?? to bypass the recursion problem?Comment #8
neograph734Well, thanks :p
I think it got inspired by paragraphs or entity reference, where more or less the same code was used.
I dont't know how this part of Drupal works exactly, so I borrowed the code.
Comment #9
jsacksick commentedoh I see
EntityReferenceItem::generateSampleValue()has similar code :), so you're forgiven :p.Comment #10
neograph734I can't even remember what I ate last week and you are asking why I did things a year ago... :p
I must have had it without initially and after I kept running into a recursion error I started looking around on how I could avoid that and ended up here. I don't think I have ever tried to just call
create()on the storage. I assumed thatgenerateSampleValue()was the only way to generate sample values.Comment #11
jsacksick commentedWell, all we need is a "sample" entity that at least has a bundle defined I guess :p.
For example, commerce, for orders has the following code:
It looks like it just need an order that has the bundle set :p. Can't really speak for other entity types, but we probably don't need more than that?
Comment #12
jsacksick commentedI rewrote the code to not use
createWithSampleValues()which removes the need for the static recursion prevention hack;I had a look at the various workflow callbacks defined by commerce/contrib, and they all seem to need the entity to have a bundle, nothing more.
I added tests coverage as well (though none of the test entities we use defines a workflow_callback that uses the entity passed.
@Neograph734: Any chance you can confirm the patch works as expected (if you're still using it?)
Comment #13
jsacksick commentedComment #14
neograph734Not actively using it, but I believe you'd get an error as soon as you went into layout builder for the order display. I'll have a look at it now.
Comment #15
neograph734Confirming that this works.
There is some other weird things happening because you need to have at least one product and one order containing a product (otherwise you will also get errors, but that is a commerce issue). Given you meet those conditions, enabling the layout builder on an order type will work and you will see transition buttons, whereas you'd previously would get an error. I think it was
I just nuked my development environment by changing something, but to ensure it was not related I had to spin up two sites in simplytest.me which took a bit longer (and made me discover the other issues).
RTBC for me.
UPDATE
Also traced the source of the nuke, indeed not related.
Comment #17
jsacksick commentedCommitted! Thanks a lot for your contribution!