In my Drupal project I have this error:

The website encountered an unexpected error. Please try again later.
Recoverable fatal error: Argument 1 passed to Drupal\Core\Entity\EntityViewBuilder::view() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /Users/team1/workspace/ga_p/modules/field_collection/src/Plugin/Field/FieldFormatter/FieldCollectionItemsFormatter.php on line 33 and defined in Drupal\Core\Entity\EntityViewBuilder->view() (line 110 of core/lib/Drupal/Core/Entity/EntityViewBuilder.php).
Drupal\Core\Entity\EntityViewBuilder->view(NULL) (Line: 33)
Drupal\field_collection\Plugin\Field\FieldFormatter\FieldCollectionItemsFormatter->viewElements(Object, 'es') (Line: 80)
Drupal\Core\Field\FormatterBase->view(Object, 'es') (Line: 259)
Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 320)
Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'search_index') (Line: 24)
Drupal\node\NodeViewBuilder->buildComponents(Array, Array, Array, 'search_index') (Line: 263)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 220)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func(Array, Array) (Line: 376)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 151)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 152)
Drupal\Core\Render\Renderer->renderPlain(Array) (Line: 480)
Drupal\node\Plugin\Search\NodeSearch->indexNode(Object) (Line: 452)
Drupal\node\Plugin\Search\NodeSearch->updateIndex() (Line: 195)
search_cron()
call_user_func_array('search_cron', Array) (Line: 391)
Drupal\Core\Extension\ModuleHandler->invoke('search', 'cron') (Line: 223)
Drupal\Core\Cron->invokeCronHandlers() (Line: 122)
Drupal\Core\Cron->run() (Line: 75)
Drupal\Core\ProxyClass\Cron->run() (Line: 65)
Drupal\automated_cron\EventSubscriber\AutomatedCron->onTerminate(Object, 'kernel.terminate', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.terminate', Object) (Line: 84)
Symfony\Component\HttpKernel\HttpKernel->terminate(Object, Object) (Line: 32)
Stack\StackedHttpKernel->terminate(Object, Object) (Line: 634)
Drupal\Core\DrupalKernel->terminate(Object, Object) (Line: 22)

Field collection version: 8.x-1.0-alpha1

I do not know how to remove this error.

Drupal Version: 8.3.4

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

javichuteck created an issue. See original summary.

orbistertius’s picture

I guess this is more or less the same error but not viewing the field collection but editing:

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\Core\Entity\Entity\EntityFormDisplay::buildForm() must implement interface Drupal\Core\Entity\FieldableEntityInterface, null given, called in /web/modules/contrib/field_collection/src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php on line 71 in Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm() (line 159 of core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php).

Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(NULL, Array, Object) (Line: 71)
Drupal\field_collection\Plugin\Field\FieldWidget\FieldCollectionEmbedWidget->formElement(Object, 0, Array, Array, Object) (Line: 322)
Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 189)
Drupal\Core\Field\WidgetBase->formMultipleElements(Object, Array, Object) (Line: 130)
Drupal\field_collection\Plugin\Field\FieldWidget\FieldCollectionEmbedWidget->formMultipleElements(Object, Array, Object) (Line: 104)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 168)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 122)
Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 115)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('contenido_canal_edit_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm('contenido_canal_edit_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
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}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
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: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

This happens only on one of my ECK Entity Bundle with a field collection (there are many where it works), I resaved all configurations. Other thing is that I am not able to add the field collections of this entity bundle to a view, here the preview disappears...
Hope someone can help or there is an other report/patch handling this.

gilmord’s picture

Hi,
Here is small temp patch to fix the issue.

olofbokedal’s picture

Updated the small patch in order to also handle the formatter. Same simple logics, it just avoids the crash.

mqanneh’s picture

This needs to be rerolled against latest dev version.

mqanneh’s picture

unrealauk’s picture

Please, review my commit to it.

Status: Needs review » Needs work
unrealauk’s picture

Corrected patch file according to the version of module -> 8.x-1.0-alpha1

Alan D.’s picture

I used this

      if ($item->value !== NULL && ($fc_item = $item->getFieldCollectionItem())) {
        $render_items[] = \Drupal::entityTypeManager()->getViewBuilder('field_collection_item')->view($fc_item);
      }

but really should be something like !$item->isEmpty() yada yada. No ide or time to play

ram4nd’s picture

Status: Needs work » Closed (won't fix)
Alan D.’s picture

Status: Closed (won't fix) » Needs work

The code for the formatter is completely unchanged so reopening for clarification:

* was this outdated magically by another change somewhere?
* the patch doesn't apply?
* you couldn't replicate?
* is the module totally unsupported?
* and / or were you just randomly closing issues?

ram4nd’s picture

Alan D.’s picture

Thanks, context is much better.

Spokje’s picture

Patch against tag 8.x-1.0-alpha which I desperately needed whilst (Oh, the irony...) in the middle of converting my field_collections into paragraphs.