Display Suite Forms does not seem to be compatible with nested entities.
Due to this, ds_forms can't be used with some modules like Scald in order to manage fields display.

The attached patch fixed this issue for me. All it does is add a parsing of $form child elements and search for additional form elements.

Could someone review this ?

Comments

brice_gato’s picture

Status: Active » Reviewed & tested by the community

This works for me.

geek-merlin’s picture

@brice_gato: Thanks for crosslinkting this in the other issues.
Please next time close the others as a dup and link here, instead of re-uploading the patch several times.

geek-merlin’s picture

Status: Reviewed & tested by the community » Needs work

This needs work as the hook still runs too early - at least for profile2.

geek-merlin’s picture

Title: Display Suite Forms module not compatible with nested entities » DS Forms does not work with Profile2, Inline Entity Form, Paragraph, Scald, ...
Category: Feature request » Bug report
Status: Needs work » Needs review
StatusFileSize
new3.58 KB

Patch flying in that adds altering hook order and fixes the issue for me (with profile2).
Raising prio as quite some important modules are blocked.
Please test and RTBC.

ifrik’s picture

The patch works for me with Scald.

gge’s picture

Patch #4 applied successfully but DS still doesn't work with Inline Entity Form.

geek-merlin’s picture

Status: Needs review » Reviewed & tested by the community

So this addreses at least profile2 and scald, let's RTBC this as of #5 and handle IEF in a followup.

captainack’s picture

Thanks for the patch guys!

Just tested it and it fixes standalone profile2 forms, but it doesn't seem to fix them if they're attached to the registration form.

captainack’s picture

Yup :( the first conditional passes ($bundle == 'user'), so the loop gets bypassed.

Furthermore, the $form_id in being passed to DS in the loop is probably gonna prevent profiles on the user_register_form from working, because $form_id will be user_register_form.

captainack’s picture

Status: Reviewed & tested by the community » Needs work

Okay so I was wrong about the second thing ($form_id is only used to check against a blacklist, which doesn't apply here). But regarding the first thing, I simply removed the else surrounding the second part, and everything seems to work. I tested:

- ds'ed profile2's own form
- ds'ed profile2 edit form attached to reg form
- ds'ed fields inside a field_collection
- non-ds'ed forms

Did you guys have a specific reason for the second block? It seems safe.

Anyway, I'll post a patch soon.

captainack’s picture

Status: Needs work » Needs review
StatusFileSize
new3.12 KB
philsward’s picture

Gave the #11 patch a try and it doesn't seem to do much with Paragraphs :-/

phily’s picture

Patch #11 works with Drupal 7.56, Display Suite 7.x-2.14 & Profile2 7.x-1.3.
Thanks

delacosta456’s picture

Patch #11 applied but doesn't work for IEF+display suite.

geek-merlin’s picture

Status: Needs review » Reviewed & tested by the community

So #11 is #4 without the else() around the second code block.
This semms safe to me (author of #4) and if (as reported) this fixes additional (inline_registration) use cases, all the better.

So based on #5, #8, #13 this fixes the issue for profile2 and scald.
I'd propose to RTBC this and fix the other integrations in a followup.

capynet’s picture

It does not work for paragraphs (at least nested)

sphism’s picture

The code in #11 just seems to alter form items that are nested one level deeper. I think paragraphs_items will always be more than that since there's the field, language, items, etc.

But regardless you need to iterate deeper since paragraphs can contain other paragraphs.

I managed to get ds form working on nested paragraphs using this code, in case it's any use to anyone:


function MY_MODULE_form_alter(form_alter(&$form, &$form_state, $form_id) {
  // Make display suite work with nested paragraphs.
  _MY_MODULE_ds_forms_form_alter_nested($form, $form_state, $form_id);
}

/**
 * Make display suite work with nested paragraphs.
 */
function _MY_MODULES_ds_forms_form_alter_nested(&$form, &$form_state, $form_id, $iterate = 0) {
  if (module_exists('ds_forms')) {
    foreach (element_children($form) as $key) {
      // Is it ok to call a hook directly like this? Seems better than
      // duplicating the form alterations manually, but also don't want to
      // trigger other hooks.
      ds_forms_form_alter($form, $form_state, $form_id);

      $form[$key]['#form_id'] = $form_id;

      // Iterate deeper.
      $is_container = $form[$key]['#type'] == 'container';
      $is_lang_wrapper = $key == $form[$key]['#language'];
      $is_paragraphs_item = $form[$key]['#entity_type'] == 'paragraphs_item';

      // Let's prevent infinite loops.
      if ($iterate < 10) {
        if ($is_container || $is_lang_wrapper || $is_paragraphs_item) {
          _MY_MODULE_ds_forms_form_alter_nested($form[$key], $form_state, $form_id, $iterate++);
        }
      }
    }
  }
}

Originally I duplicated ds_forms_form_alter alterations into here but that seems dangerous, i don't think there's any issue calling the hook function directly like that. Anyone have any thoughts on that?

There's probably a better conditional to check if we want to iterate deeper, maybe looping through the field items parents and seeing if any of them are paragraphs, etc. Anyone know if there's a clever check for all fields that would need deeper iteration to cover paragraphs, inline entity form, scald, etc.