When viewing the detail of an entity that has a remote_image field with an empty title, PHP throws the following error:

Notice: Undefined index: #title in Drupal\remote_image\Plugin\Field\FieldFormatter\RemoteImageWithMetadataFormatter->viewElements() (line 49 of remote_image/src/Plugin/Field/FieldFormatter/RemoteImageWithMetadataFormatter.php).

Drupal\remote_image\Plugin\Field\FieldFormatter\RemoteImageWithMetadataFormatter->viewElements(Object, 'es') (Line: 80)
Drupal\Core\Field\FormatterBase->view(Object, 'es') (Line: 262)
Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array) (Line: 321)
Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 263)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 220)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func(Array, Array) (Line: 378)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 582)
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: 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: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
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: 666)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
require('index.php') (Line: 96)

The RemoteImageWithMetadataFormatter access directly to $image['#title'] without checking if it is defined.

But RemoteImageFormatter only defines the #title key if the setting title_field is enabled on the field.

Comments

tucho created an issue. See original summary.

tucho’s picture

Status: Active » Needs review
StatusFileSize
new1.08 KB

I uploaded a patch the fix this issue.

It just verifies if the #title key is defined before adding it to the render array.

gaurav.kapoor’s picture

Status: Needs review » Reviewed & tested by the community

Tested by creating an entry without title and noticed the warning message. Applied the patch and the warning isn't shown anymore. Thanks for working on this.

  • gaurav.kapoor committed 6744aea on 8.x-1.x authored by tucho
    Issue #2987327 by tucho, gaurav.kapoor: Undefined index: #title in...
gaurav.kapoor’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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