Problem/Motivation

Upon insert of a new paragraph from the off-canvas dialog, a php notice is shown for Undefined index: #id in template_preprocess_paragraphs_add_dialog__categorized()

Steps to reproduce

Enable error display in the site.
In a paragraphs field with the following Paragraphs Experimental form widget settings:

  • Title: Paragraph
  • Plural title: Paragraphs
  • Edit mode: Closed
  • Closed mode: Summary
  • Autocollapse: All
  • Add mode: Modal form
  • Form display mode: default
  • Features: Duplicate, Collapse / Edit all, Add above
  • Use off-canvas dialog
  • Display paragraphs in dialog as: List
  • Number of easy-access-buttons: 2

Click the "triple dot" control provided by Paragraphs Features.
Choose a paragraph.
Observe the following

 Notice: Undefined index: #id in template_preprocess_paragraphs_add_dialog__categorized() (line 294 of /var/www/docroot/modules/contrib/paragraphs_ee/paragraphs_ee.module). =>
array:24 [▼
  "23: template_preprocess_paragraphs_add_dialog__categorized()" => array:2 [▶]
  "22: Drupal\Core\Theme\ThemeManager->render()" => array:2 [▶]
  "21: Drupal\Core\Render\Renderer->doRender()" => array:2 [▶]
  "20: Drupal\Core\Render\Renderer->doRender()" => array:2 [▶]
  "19: Drupal\Core\Render\Renderer->render()" => array:2 [▶]
  "18: Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()" => array:1 [▶]
  "17: Drupal\Core\Render\Renderer->executeInRenderContext()" => array:2 [▶]
  "16: Drupal\Core\Render\Renderer->renderRoot()" => array:2 [▶]
  "15: Drupal\Core\Render\MainContent\OffCanvasRenderer->renderResponse()" => array:2 [▶]
  "14: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()" => array:2 [▶]
  "13: call_user_func()" => array:1 [▶]
  "12: Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()" => array:2 [▶]
  "11: Symfony\Component\HttpKernel\HttpKernel->handleRaw()" => array:2 [▶]
  "10: Symfony\Component\HttpKernel\HttpKernel->handle()" => array:2 [▶]
  " 9: Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle()" => array:2 [▶]
  " 8: Drupal\Core\StackMiddleware\Session->handle()" => array:2 [▶]
  " 7: Drupal\Core\StackMiddleware\KernelPreHandle->handle()" => array:2 [▶]
  " 6: Drupal\page_cache\StackMiddleware\PageCache->pass()" => array:2 [▶]
  " 5: Drupal\page_cache\StackMiddleware\PageCache->handle()" => array:2 [▶]
  " 4: Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()" => array:2 [▶]
  " 3: Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()" => array:2 [▶]
  " 2: Stack\StackedHttpKernel->handle()" => array:2 [▶]
  " 1: Drupal\Core\DrupalKernel->handle()" => array:2 [▶]
  " 0: main()" => array:2 [▶]
]

Proposed resolution

Use a conditional expression to build the id string.

Remaining tasks

None

User interface changes

None

API changes

None to our knowledge

Data model changes

None to our knowledge.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

FatherShawn created an issue. See original summary.

fathershawn’s picture

Status: Active » Needs review

Investigating with xdebug, it seems that $vars['element']['#id'] is set on page build when this function runs, but it is not set when it is run on off-canvas dialog build.

  • FatherShawn committed 4068818 on 8.x-1.x
    Issue #3197568: Notice: Undefined index: #id in...
stborchert’s picture

Version: 8.x-1.7 » 8.x-1.x-dev
Status: Needs review » Fixed

Thanks for fixing this. I never saw this happen before, but its good to be safe here.

Status: Fixed » Closed (fixed)

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