Problem/Motivation

As a site builder, I want to allow the creation of blocks on an entity, where these blocks will be single use. This is similar to adding blocks in layout_builder and the block type involved is InlineBlock. This issue is not about using layout builder though, it happens that layout builder provides the InlineBlock plugin.

I've added a general question about my problem on stack exchange as well.

Steps to reproduce

  1. Install block_field, layout_builder
  2. Create a custom block type with one field, just some text
  3. (Do not create any blocks in the custom block library)
  4. New node type "page"
  5. Add a block_field field to "page", and reference the new plugin, which will be type "inline block" (provider is Layout Builder)
  6. Create a node, populate by choose the block type and filling in the form.
  7. Hit save

Resulting error :

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\Component\Utility\NestedArray::getValue() must be of the type array, null given, called in /app/web/core/lib/Drupal/Core/Field/WidgetBase.php on line 414 in Drupal\Component\Utility\NestedArray::getValue() (line 69 of core/lib/Drupal/Component/Utility/NestedArray.php).
Drupal\Component\Utility\NestedArray::getValue(NULL, NULL) (Line: 414)
Drupal\Core\Field\WidgetBase->flagErrors(Object, Object, Array, Object) (Line: 265)
Drupal\Core\Entity\Entity\EntityFormDisplay->flagWidgetsErrorsFromViolations(Object, Array, Object) (Line: 252)
Drupal\Core\Entity\Entity\EntityFormDisplay->validateFormValues(Object, Array, Object) (Line: 181)
Drupal\layout_builder\Plugin\Block\InlineBlock->blockValidate(Array, Object) (Line: 207)
Drupal\Core\Block\BlockBase->validateConfigurationForm(Array, Object) (Line: 238)
Drupal\block_field\Plugin\Field\FieldWidget\BlockFieldWidget::validate(Array, Object, Array)
call_user_func_array(Array, Array) (Line: 280)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 236)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 236)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 236)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'node_article_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('node_article_form', Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('node_article_form', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 67)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->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: 49)
Asm89\Stack\Cors->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: 705)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Proposed resolution

It would be great if this module supported the core "InlineBlock" block plugin type.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

sime created an issue. See original summary.

sime’s picture

Issue summary: View changes

Updated intro to specify the problem is with node fields not just paragraphs.

sime’s picture

acbramley’s picture

CP from SO:

The block_field module is designed to reference block plugins rather than block content. I think what you want here is an entity reference field with an inline entity form or entity browser.

It's likely block field has never been tested with layout_builder enabled (where the InlineBlock plugin comes from) so that's where this confusion is coming from!

What we should do here I think is hide the InlineBlock plugin from block_field's available choices.

sime’s picture

Makes sense - thanks for the stack exchange response!

damondt’s picture

I agree that removing the entity reference option for block plugins is ideal so that people will drill down to find custom block content or other block content to reference.

If others encounter this I also got errors trying to use the inline entity form, but had luck using entity browser after creating a block entity browser through the gui.

Berdir’s picture

The error is coming from the block plugin itself so not sure we can do something about that. That said I' don't fully agree with the answer there, because using block_field would still allow you to mix things, use a block content entity in one place and a view in another.

However, if you want inlined non-reusable content, then there might be better approaches for that than this module + InlineBlock.