Hi I currently have this version of ds in composer.lock: "version": "8.x-3.0-beta4+0-dev", "datestamp": "1493795284"

When I create a paragraph entity that has no fields yet, after I try to switch its layout to a new one using DS / Manage Display, I get the following error.

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to _ds_sort_fields() must be of the type array, null given, called in /var/www/thp/web/modules/contrib/ds/includes/field_ui.inc on line 399 in _ds_sort_fields() (line 1404 of modules/contrib/ds/includes/field_ui.inc).
_ds_sort_fields(NULL, 'weight') (Line: 399)
ds_field_ui_layouts_save(Array, Object)
call_user_func_array('ds_field_ui_layouts_save', Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder->processForm('entity_view_display_edit_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('entity_view_display_edit_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
[.......]

This may be a bug on the Paragraphs side however. I put it here since it was DS related functions throwing the error. Please reassign to Paragraphs project if it is really a matter to be addressed on that side. However if generally speaking DS can't handle entities without fields something should probably be adjusted on this side.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

HongPong created an issue. See original summary.

aspilicious’s picture

What version of core are you using?

HongPong’s picture

core version 8.3.2. Paragraphs is at "version": "8.x-1.1+16-dev", "datestamp": "1492678144" in the lockfile.

aspilicious’s picture

Status: Active » Needs review
FileSize
1.06 KB

Could you test this patch?

StryKaizer’s picture

Status: Needs review » Needs work
FileSize
117.11 KB

Patch in #4 solves error described. Thx!

This fix does show a new issue, where the custom coded DS fields are rendered below instead of in the expected regions areas, see screenshot.

workplaysleep’s picture

Confirm on the issue @StryKaizer mentions

DamienMcKenna’s picture

The patch gets past the initial error, but now I get two warnings:

  • Warning: asort() expects parameter 1 to be array, null given in _ds_sort_fields() (line 1412 of modules/contrib/ds/includes/field_ui.inc).
    _ds_sort_fields(Array, 'weight') (Line: 399)
  • Warning: Invalid argument supplied for foreach() in _ds_sort_fields() (line 1413 of modules/contrib/ds/includes/field_ui.inc).
    _ds_sort_fields(Array, 'weight') (Line: 399)

This is in addition to the bug mentioned by @StryKaizer.

Incidentally, if I apply the patch, save the form (so the warnings above are shown) and then revert the patch the problems still happen.

Some other things to note:

  • On this Paragraph Type I want to attach a view using EVA, there are no other fields.
  • Another Paragraph Type is set up the same way but works correctly.
Dozz’s picture

The custom coded fields are rendered at the bottom because in EntityDisplayFormBase:form(), when there are no fields, the field ui table is not added so DS can't add anything to it.

In the patch attached, I add this table when it doesn't exist and attach the field_ui library.
Maybe it would have been a better solution to make EntityDisplayFormBase:form() add the table even when there are no fields, though.

Dozz’s picture

Status: Needs work » Needs review

The custom coded fields are rendered below because in EntityDisplayFormBase:form() the field ui table is not added when there are no fields so DS can't add anything to it.

In the patch attached, I add this table to the form when it doesn't exist and attach the field_ui library.

Maybe it would have been a better solution to make EntityDisplayFormBase:form() add the table even when there are no fields, though.

Dozz’s picture

My comment didn't get posted with my patch for some reason, second attempt:

The custom coded fields are rendered at the bottom because in EntityDisplayFormBase:form() does not add the field ui table when there are no fields so DS can't add anything to this table.

In the patch attached, I add this table to the form when it doesn't exist and attach the field_ui library.

Maybe it would have been a better solution to make EntityDisplayFormBase:form() add the table even when there are no fields, though.

Dozz’s picture

My comment didn't get posted with my patch for some reason, second attempt:

The custom coded fields are rendered at the bottom because in EntityDisplayFormBase:form() does not add the field ui table when there are no fields so DS can't add anything to this table.

In the patch attached, I add this table to the form when it doesn't exist and attach the field_ui library.

Maybe it would have been a better solution to make EntityDisplayFormBase:form() add the table even when there are no fields, though.

Dozz’s picture

My comment didn't get posted with my patch for some reason, second attempt:

The custom coded fields are rendered at the bottom because in EntityDisplayFormBase:form() does not add the field ui table when there are no fields so DS can't add anything to this table.

In the patch attached, I add this table to the form when it doesn't exist and attach the field_ui library.

Maybe it would have been a better solution to make EntityDisplayFormBase:form() add the table even when there are no fields, though.

NWOM’s picture

FileSize
4.73 KB

#12 fixed my issue! Thank you. Here is the patch again, and will hopefully be attached correctly.

damontgomery’s picture

Status: Needs review » Reviewed & tested by the community

We've used #13 and I had a look over the code, so I'm marking this as tested.

The comments in the patch are helpful. I think it might also be useful to add comments about why we need to cast to an array in a few places, although I can make some guesses.

$fields = _ds_sort_fields((array) $form_state->getValue('fields'), 'weight');

Please update if this needs more work / testing.

Thanks!

swentel’s picture

Status: Reviewed & tested by the community » Needs review

So the patch fixes the fatal errors, that's at least a good step. The only remaning thing is that if you move a field from disabled to a region, the throbber keeps spinning (in my testing, I only have the 'Bundle name' field available in parapgraphs). It doesn't trigger a JS or request error, and hitting save is fine too. I'm going to check what's wrong here to see if I can get rid of that, maybe there's a missing library or so, because it might confuse users.

swentel’s picture

Checked with a different entity display, and when dropping a field, a request should be triggered to admin/structure/paragraphs_type/{paragraph_type}/display?ajax_form=1&_wrapper_format=drupal_ajax

This doesn't happen when there are no fields. As mentioned in my previous comment, it doesn't break anything, checking some more now.

swentel’s picture

FileSize
6.43 KB

Ok, figured out the throbber. That's because the 'refresh' button isn't available (that's a hidden button at the bottom of the field ui table). Adding that as well triggers the request and the throbber goes away, and there are no errors. However, you're getting the many instances of the 'here are no fields yet added. You can add new fields on the Manage fields page.' warning.

Attached patch clears that warning and adds the refresh button.

swentel’s picture

FileSize
1.43 KB

This is the (badly taken) diff.

stijnd’s picture

Applied #17. Issue fixed.

  • Core version 8.9.13
  • Display Suite 8.x-3.9
  • Paragraphs 8.x-1.12
swentel’s picture

Status: Needs review » Reviewed & tested by the community

Ok, cool, will commit soon

  • swentel committed 279de1b on 8.x-3.x
    Issue #2877487 by swentel, Dozz, aspilicious, NWOM, StryKaizer:  Setting...

  • swentel committed fc69bad on 8.x-4.x
    Issue #2877487 by swentel, Dozz, aspilicious, NWOM, StryKaizer:  Setting...
swentel’s picture

Status: Reviewed & tested by the community » Fixed

committed and pushed, thanks all!

Status: Fixed » Closed (fixed)

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