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.

Comments

Neograph734 created an issue. See original summary.

neograph734’s picture

Status: Active » Needs review
StatusFileSize
new2.87 KB

First attempt to return a sensible value.

Status: Needs review » Needs work

The last submitted patch, 2: 3137212-StateItem_generateSampleValue-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

neograph734’s picture

Status: Needs work » Needs review
StatusFileSize
new3.17 KB

Missed the use statements...

neograph734’s picture

Adding this is a child issue of Commerce #2952529: Support for Layout Builder module.

neograph734’s picture

jsacksick’s picture

Status: Needs review » Needs work

The code is very ugly :p, especially the recursion part...

Maybe we could getaway with simply calling the create() on the storage instead of createWithSampleValues()?? to bypass the recursion problem?

neograph734’s picture

Well, 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.

jsacksick’s picture

oh I seeEntityReferenceItem::generateSampleValue() has similar code :), so you're forgiven :p.

neograph734’s picture

I 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 that generateSampleValue() was the only way to generate sample values.

jsacksick’s picture

Well, 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:

  public static function getWorkflowId(OrderInterface $order) {
    $workflow = OrderType::load($order->bundle())->getWorkflowId();
    return $workflow;
  }

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?

jsacksick’s picture

Status: Needs work » Needs review
StatusFileSize
new5.09 KB

I 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?)

jsacksick’s picture

StatusFileSize
new5.1 KB
neograph734’s picture

Not 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.

neograph734’s picture

Status: Needs review » Reviewed & tested by the community

Confirming 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

The website encountered an unexpected error. Please try again later.
Error: Call to a member function generateSampleItems() on null in Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem::generateSampleValue() (line 524 of modules/contrib/entity_reference_revisions/src/Plugin/Field/FieldType/EntityReferenceRevisionsItem.php).

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.

  • jsacksick committed 634dc5d on 8.x-1.x
    Issue #3137212 by Neograph734, jsacksick: Implement a...
jsacksick’s picture

Status: Reviewed & tested by the community » Fixed

Committed! Thanks a lot for your contribution!

Status: Fixed » Closed (fixed)

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