Layout builder does not work when there is a product attribute without values

Created on 27 September 2020, about 4 years ago
Updated 21 November 2023, about 1 year ago

Problem/Motivation

When attempting to edit a layout for a product that uses an attribute without options, layout builder fails generating the sample values.

Steps to reproduce

- Install commerce on a clean site
- Go to Administration > Commerce > Product attributes
- Create a product attribute, but 'forget' to add one or more options. (This is a somewhat realistic scenario after a config import without content)
- Head over to Administration > Commerce > Configuration > Product types > Edit Default > Manage display
- Enable Layout builder
- Click the manage layout button

Proposed resolution

implement generateSampleValue() for product attributes?

Remaining tasks

User interface changes

API changes

Data model changes

Stack trace

The website encountered an unexpected error. Please try again later.

Drupal\Core\Entity\EntityStorageException: No entity bundle was specified in Drupal\Core\Entity\ContentEntityStorageBase->createWithSampleValues() (line 147 of core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php).

Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::generateSampleValue(Object) (Line: 253)
Drupal\Core\Field\FieldItemList->generateSampleItems() (Line: 162)
Drupal\Core\Entity\ContentEntityStorageBase->createWithSampleValues('default', Array) (Line: 321)
Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::generateSampleValue(Object) (Line: 253)
Drupal\Core\Field\FieldItemList->generateSampleItems() (Line: 162)
Drupal\Core\Entity\ContentEntityStorageBase->createWithSampleValues('default', Array) (Line: 321)
Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::generateSampleValue(Object) (Line: 253)
Drupal\Core\Field\FieldItemList->generateSampleItems() (Line: 162)
Drupal\Core\Entity\ContentEntityStorageBase->createWithSampleValues('default') (Line: 68)
Drupal\commerce_product\ContextProvider\ProductVariationContext->getRuntimeContexts(Array) (Line: 108)
Drupal\commerce_product\ContextProvider\ProductVariationContext->getAvailableContexts() (Line: 97)
Drupal\Core\Plugin\Context\LazyContextRepository->getAvailableContexts() (Line: 44)
Drupal\layout_builder\Element\LayoutBuilder->getAvailableContexts(Object) (Line: 250)
Drupal\layout_builder\Element\LayoutBuilder->buildAdministrativeSection(Object, 0) (Line: 123)
Drupal\layout_builder\Element\LayoutBuilder->layout(Object) (Line: 97)
Drupal\layout_builder\Element\LayoutBuilder->preRender(Array)
call_user_func_array(Array, Array) (Line: 100)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725', 'silenced_deprecation', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 444)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
🐛 Bug report
Status

Fixed

Version

2.0

Component

Product

Created by

🇳🇱Netherlands neograph734 Netherlands

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024