Getting the following error after upgrading the lastest version of Paragraphs 8.x dev:

Notice: Undefined offset: 1 in paragraphs_preprocess_field_multiple_value_form() (line 284 of modules/paragraphs/paragraphs.module).
paragraphs_preprocess_field_multiple_value_form(Array, 'field_multiple_value_form', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('field_multiple_value_form', Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 448)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 448)
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: 574)
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) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 149)
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: 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: 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)

The page is a node edit page with a paragraph attachment. If I remove the sole attached paragraph the error goes away. If I add it back again (with no values) the error returns.

If I roll back to the previous dev version of paragraphs (8.x-1.1+48-dev), the error goes away.

Looks like new code. This function doesn't exist in the previous version of paragraphs:

function paragraphs_preprocess_field_multiple_value_form(&$variables) {
  if (count($variables['element']['#field_parents']) === 0 && isset($variables['table']['#rows'])) {
    // Find header_action and move to header.
    // @see template_preprocess_field_multiple_value_form()
    foreach ($variables['table']['#rows'] as $i => $row) {
      if (isset($variables['table']['#rows'][$i]['data'][1]['data']['#attributes']['class'])) {
        if ($variables['table']['#rows'][$i]['data'][1]['data']['#attributes']['class'][1] === 'paragraphs-header-actions') {
          $variables['table']['#header'][0]['data'] = [
            'title' => $variables['table']['#header'][0]['data'],
            'button' => $variables['table']['#rows'][$i]['data'][1],
          ];
          unset($variables['table']['#rows'][$i]);
          break;
        }
      }
    }
  }
}

Digging into this with a bit of debug/kint, it looks like $variables['table']['#rows'][$i]['data'][1]['data']['#attributes']['class'] is an empty array for me. So it passes isset($variables['table']['#rows'][$i]['data'][1]['data']['#attributes']['class']), but $variables['table']['#rows'][$i]['data'][1]['data']['#attributes']['class'][1] is undefined.

If I make the logical change:

if (isset($variables['table']['#rows'][$i]['data'][1]['data']['#attributes']['class'])) {

and modify this to:

if (isset($variables['table']['#rows'][$i]['data'][1]['data']['#attributes']['class'][1])) {

The error goes away.

I could submit this as a patch, but I don't know enough about the new function to understand why it's there in the first place.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TrevorBradley created an issue. See original summary.

johnchque’s picture

Makes sense to me to do the change you suggest. Would you provide a patch with that small change so we could see if it breaks any test?
As far as I know, the code was added for having a "Collapse all" button. :)

TrevorBradley’s picture

Berdir’s picture

Status: Active » Needs work

Thanks. I noticed a similar problem in #2825575: Introduce a Drag & Drop Mode and fixed it differently, with an in_array() check.

I'm working hard on finishing that issue, but I can't make a promise when it will be committed as it is one of the most complicated things I've ever worked on. Feel free to take my fix there, verify it fixes the problem for you and post a standalone patch here for this.

TrevorBradley’s picture

Verified that the patch for #2825575: Introduce a Drag & Drop Mode also fixes this problem.

Andrew Gorokhovets’s picture

Hi, I updated the patch because it still needed.

Also this error comes with Bricks integration, please take a look the video.
Video

As mention @TrevorBradley the problem is in paragraphs_preprocess_field_multiple_value_form()
debug

So I updated the patch.
Please take a look.

Status: Needs review » Needs work

The last submitted patch, 6: undefined-offset-in_paragraphs_preprocess_field_multiple_value_form2895992-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

_gradient_’s picture

The issue is still actual. Here's the updated patch of @Andrew Gorokhovets for the last module version.

2pha’s picture

Got this today too on an established site to which I added the paragraphs module (8.x-1.14).
I had not added any paragraphs to the site yet, but when I navigated to a page to add a node (which had a multiple value textfield) I encountered this error.
Patch #8 fixed it.

2pha’s picture

Status: Needs work » Needs review