Problem/Motivation

When an inline entity form is used to create content, the conditional_field.js is not loaded and the conditional field rules do not run.

Steps to reproduce

  1. Download Drupal 8.9.0, Inline Entity Form 8.x-1.0-rc6; and clone Conditional Fields branch 8.x-1.x (when I wrote this, the latest commit was 9c9930e)
  2. Install Drupal using the Standard install profile. When that is done, install Conditional Fields and Inline Entity Form
  3. Go to /admin/structure/types/manage/article/fields, add a Boolean field named "Has image" (machine name field_has_image)
  4. Go to /admin/structure/types/manage/article/conditionals and add a condition/dependency as follows:
    1. Target field = field_image
    2. Controlled by = field_has_image
    3. The target field = visible
    4. when the control field is Checked
    5. Click Add dependency
  5. Go to /node/add/article. Observe that when "Has image" is unchecked, the "Image" field is hidden; and when "Has image" is checked, the "Image" field is shown.
  6. Go to /admin/structure/types/manage/page/fields, add a field of type [Entity] Reference to entities of type Content named "Related article" (machine name field_related_article). Use the default configuration.
  7. Go to /admin/structure/types/manage/page/form-display and change the widget from the default to Inline entity form - Simple. Click Save
  8. Go to /node/add/page:
    • Actual behavior: Observe that the "Image" field is always shown regardless of the state of the "Has image" field.
    • Expected behavior: When "Has image" is unchecked, the "Image" field is hidden; and when "Has image" is checked, the "Image" field is shown

Analysis

As originally mentioned in #1, the conditional_fields.js file is missing, and the drupalSettings JSON which controls it is missing (the drupalSettings JSON for the working article form is...

"conditionalFields": {
  "effects": {
    "#edit-field-image-wrapper": []
  }
},

)

The missing library and drupalSettings is because conditional_fields_form_after_build() doesn't attach the libraries. It doesn't attach the libraries because it doesn't detect any conditional fields. Notably, though, it only runs for the outer form (i.e.: the basic page form in the steps to reproduce). It doesn't detect any conditional fields because $this->form['#conditional_fields'] does not exist in the outer form. $this->form['#conditional_fields'] is not added to the outer form because conditional_fields_element_after_build() doesn't detect that the outer form is associated with the inner form's entity/bundle. conditional_fields_element_after_build() detects whether a form is associated with an entity/bundle by calling $form_state->getBuildInfo()['callback_object']->getEntity().

Proposed resolution

Inject information about the inner form's entity so that it can be detected when conditional_fields_element_after_build() runs for the outer form.

Remaining tasks

  1. Figure out how to inject information about the inner form's entity. (done as of #27)
  2. Update the issue summary to better explain what the problem(s) are, how we could go about fixing them, and identify any remaining issues
  3. Update the patch from #27 to identify the correct element to attach conditional field actions to.
  4. Statically cache DependencyHelper for different entity types / bundles: #1161314-235: Add basic Field Group support for ANDing conditions
  5. Review and feedback
  6. RTBC and maintainer feedback
  7. Commit and release

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

To be determined.

CommentFileSizeAuthor
#95 2856720-support-for-inline-entity-form-95.patch23.35 KBramil g
#89 interdiff.txt1.13 KBramil g
#89 2856720-support-for-inline-entity-form-89.patch23.26 KBramil g
#87 interdiff.txt712 bytesramil g
#87 2856720-support-for-inline-entity-form-87.patch23.13 KBramil g
#86 2856720-support-for-inline-entity-form-86.patch23.09 KBramil g
#83 interdiff_80-83.txt1.5 KBsaurabh-2k17
#83 2856720-support_for_inline_entity_form-83.patch22.88 KBsaurabh-2k17
#80 interdiff_74-80.txt3.41 KBsaurabh-2k17
#80 2856720-support_for_inline_entity_form-80.patch22.76 KBsaurabh-2k17
#74 2856720-support_for_inline_entity_form-74.patch21.79 KBnevergone
#72 inline_entity_form_conditional_fields_dev.patch60.27 KBVladimir Tanovic
#68 support-for-inline-entity-form-2856720-67.patch60.32 KBlexsoft
#66 support-for-inline-entity-form-2856720-66.patch54.58 KBlexsoft
#51 2856720-51.patch47.28 KBnevergone
#38 Screen Recording 2020-10-20 at 21.15.07.mov1.97 MBdarrenwh
#35 2856720-35.patch44.75 KBNightAr
#33 2856720-33.patch41.65 KBNightAr
#27 2856720-27.patch8.25 KBnuez
#4 2856720-4-IEF-support.patch6.4 KBniko-
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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Topplestack created an issue. See original summary.

Topplestack’s picture

So far all I can tell is that it is related to the $form['#attached']['js'] method of attaching JS to a module where in Drupal 7 the same problem existed, but the drupal_add_js() function could be used instead. Since drupal_add_js() has been deprecated in D8, it's not an option. So it looks like the $form['#attached']['js'] is actually at fault.

niko-’s picture

My investigation shows that we need pass embeded entity for example via form state storage and make special handle method in conditional_fields_element_after_build for inline entities

niko-’s picture

Status: Active » Needs review
FileSize
6.4 KB
pavithra.raman’s picture

Tried this patch, but while calling the inline entity form I get this error

Recoverable fatal error: Argument 2 passed to Drupal\Component\Utility\NestedArray::getValue() must be of the type array, null given, called in /Users/pavithra.raman/DevDesktop/Sites/cddemo10-dev/docroot/modules/contrib/inline_entity_form/inline_entity_form.module on line 305 and defined in Drupal\Component\Utility\NestedArray::getValue() (line 69 of core/lib/Drupal/Component/Utility/NestedArray.php).
Drupal\Component\Utility\NestedArray::getValue(Array, NULL) (Line: 305)
inline_entity_form_get_element(Array, Object) (Line: 96)
conditional_fields_form_after_build(Array, Object)
call_user_func_array('conditional_fields_form_after_build', Array) (Line: 1053)
Drupal\Core\Form\FormBuilder->doBuildForm('node_page_form', Array, Object) (Line: 557)
Drupal\Core\Form\FormBuilder->processForm('node_page_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object) (Line: 113)
Drupal\node\Controller\NodeController->add(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
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: 38)
Drupal\jsonapi\StackMiddleware\FormatSetter->handle(Object, 1, 1) (Line: 48)
Asm89\Stack\Cors->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)
xavier.masson’s picture

I've the same problem, when you check the Drupal 7 implementation, it's really different the use the field to retrieve $entity_type and $bundle (it's the right way after several tests). Using the $build_info = $form_state->getBuildInfo(); return the root parent form entity_type and bundle, not the inline entity.

Code below is the Drupal 7 implementation, and returning right values in Drupal 8.

  if (isset($field['#entity_type'], $field['#bundle'])) {
    $entity_type = $field['#entity_type'];
    $bundle = $field['#bundle'];
  }
  elseif (isset($form['#entity_type'], $form['#bundle'])) {
    $entity_type = $form['#entity_type'];
    $bundle = $form['#bundle'];
  }
  else {
    return $element;
  }

The second issue i've seen, it's the inline entity form fields do not exists in this form :

$form = &$form_state->getCompleteForm();
Topplestack’s picture

Status: Needs review » Needs work
xavier.masson’s picture

Up, no one to work on this major issue ?

tisteegz’s picture

Is this just talking about conditional fields within an inline entity form or also about the inline entity form field being a conditional field itself?

I have fields which I only want to display if my entity reference (using inline entity form) has a value but nothing seems to be happening?

Topplestack’s picture

This is specific to conditional fields on an entity being displayed via an inline entity form.

colan’s picture

#5 looks a lot like #2950955: Type Error generated in conditional_fields_evaluate_dependencies(). Are you sure it's related to IEF?

Topplestack’s picture

I'll update conditional fields and test as soon as I can. Likely early next week.

achap’s picture

colan, I tried applying the patch that you linked in #11 but it didn't appear to load the conditional field's js. I guess they are separate issues then.

achap’s picture

ah... completely missed that you were talking to the commenter from #5. My bad.

scott.whittaker’s picture

Just noting that the patch in #4 gives me a 500 error creating IEF content:

TypeError: Argument 2 passed to Drupal\Component\Utility\NestedArray::getValue() must be of the type array, null given, called in inline_entity_form/inline_entity_form.module on line 305
vbory’s picture

Does anyone have any updates regarding this issue?

scott.whittaker’s picture

Not from me unfortunately, I ended up re-implementing conditional fields with custom javascript.

If you want to do the same, you'll be able to catch IEF Ajax callbacks using Drupal.behaviours. Here's an example:

Drupal.behaviors.custom_conditional_fields = {
  attach: function (context) {
    if (context.doctype) {
      // this is the inital page load

    } else if ($(context).attr('id') && $(context).attr('id').substr(0,18) == 'inline-entity-form') {
      // ajax loaded ief content
      let ief_type = $(context).find(">:first-child").attr('id').split('--')[0];
      // console.log('Conditional fields for ' + ief_type);
      if (ief_type.substr(0, 29) == 'edit-field-whatever') {
        conditional_field(
          $(context).find('.field--name-field-macroinvertebrate-method select'),
          $(context).find('.field--name-field-stream-type select'),
          [
            { 'type': 'filter', 'selected': ['83'], 'available': ['86','85'] },
            { 'type': 'filter', 'selected': ['84'], 'available': ['87'] },
          ]
        );
       ...
cweldon’s picture

Any updates on this issue? Anything I can do to help?

yuseferi’s picture

I have the same issue with 8.x-1.x-alfa4.
doesn't work with inline form complex form.

peter.thorndycraft’s picture

We have the same issue as above, inline complex forms are not adhering to the conditional fields settings

colan’s picture

#8, #16, and #18: Comments like these (e.g. "Are there any updates?" and "Why isn't anyone working on this?") are simply noise. Please stop posting them as they don't move anything further along. If there were any updates, they'd be posted here. And nobody's working on it because nobody else is paying them. That's how open-source software development works.

#18: Your offer to help is appreciated. What we need it an updated patch the fixes the problem above. Are you either (1) able to provide one yourself, or (2) pay someone else to do it?

mebel192’s picture

Mhh Inline entity form and conditionnal fields not working i disable conditionnal field inline entity form work.

setup:
1- Add content type member
2- Add 2 fields entity ref with taxonomy
3- in form use widget inline entity form complexe for two field with permission only select taxo no creation.

create new member
in the entity field enter noting and clic add... after that clic cancel.

the fields just clone the last fields entity

very wierd, help

chriscalip’s picture

I am trying to move this issue forward.

Here are my initial findings.

The inline_entity_form provides field widgets (inline_entity_form_simple & inline_entity_form_complex) for field types, entity_reference & entity_reference_revisions. Both field widgets then provide Render Element Type, inline_entity_form, ie. Drupal\inline_entity_form\Element\InlineEntityForm. The render element type, inline_entity_form, then presents an entity form based on either Drupal\inline_entity_form\Form\EntityInlineForm or Drupal\inline_entity_form\Form\NodeInlineForm.

The conditional_fields module is currently geared towards Drupal\node\NodeForm. Fortunately, inline_entity_form, provides a hook for integration. Other modules have integrated with inline_entity_form via implementation of hook_inline_entity_form_entity_form_alter.
For example: auto_entitylabel_inline_entity_form_entity_form_alter, geocoder_field_inline_entity_form_entity_form_alter, and field_group_inline_entity_form_entity_form_alter.

At this point in time, I believe a similar hook might do the trick. Initially I thought an updated https://www.drupal.org/files/issues/2856720-4-IEF-support.patch per deprecation of `conditional_fields.api.inc` in favor of `src/ConditionalFieldsFormHelper.php` would be enough. I don't believe an update on `src/ConditionalFieldsFormHelper.php` would be necessary .. hopefully integration through hook would be enough.

colan’s picture

The work happening in #1161314: Add basic Field Group support for ANDing conditions may be helpful as there's a fair amount of refactoring to allow for nested fields. Would it make sense to postpone this on that one?

chriscalip’s picture

#24 @colan

The work needed is an abstracted utility that adds/processes conditional-fields given an entity-form.

The situation is that a form can have field/fields with each field can have multiple values (entity-references) and each of those
entity-reference value is an entity-form.

EG. node has entity-reference fields field_a, field_b which have multiple values thus multiple entity-forms.
each entity-form is then passed to conditional_fields_attach_fields($entity_form, $context);

node-form
--field-a
----widget-0 entity-form as entity-form-field-a-0
----widget-1 entity-form as entity-form-field-a-1
----widget-N entity-form as entity-form-field-a-N
--field-b
----widget-0 entity-form as entity-form-field-b-0
----widget-1 entity-form as entity-form-field-b-1
----widget-N entity-form as entity-form-field-b-N

So then:

conditional_fields_attach_fields($${'entity-form-field-a-0'}, $context);
conditional_fields_attach_fields($${'entity-form-field-a-1'}, $context);
conditional_fields_attach_fields($${'entity-form-field-a-N'}, $context);
conditional_fields_attach_fields($${'entity-form-field-b-0'}, $context);
conditional_fields_attach_fields($${'entity-form-field-b-1'}, $context);
conditional_fields_attach_fields($${'entity-form-field-b-N'}, $context);
colan’s picture

Issue summary: View changes

Added missing link to IEF in IS.

nuez’s picture

Status: Needs work » Needs review
FileSize
8.25 KB

I've been doing some work on this.

  1. Currently, conditional fields heavily relies on the assumption that all field dependencies are available in the root the form array. See for example:

    $form['#conditional_fields'][$dependee['#parents'][0]]['parents'] = $dependee['#array_parents'];

    $dependee['#parents'][0]

  2. Another assumption is that the conditional fields apply to the entity that belongs the complete form. However for inline entity forms the form object entity is not the same as the entity that belongs to the IEF. I suggest to first look at the entity type, bundle and field name that belongs to the field widget, before looking at the complete form entity.
  3. The #after_build property doesn't seem to be added to form elements within the inline entity form. I've used the hook_inline_entity_form_entity_form_alter hook to add them.
  4. I'm still running the existing tests locally. Obviously this needs tests too. Let's see what the testbot thinks.
  5. #24 Refactoring in Field Group Issue

    The work happening in #1161314: Field Group support may be helpful as there's a fair amount of refactoring to allow for nested fields. Would it make sense to postpone this on that one?

    I've looked into that one but it looks like the issues are not so much related.

    I have seen that there is a change in the conditional_fields_load_dependencies function that won't work with this patch because it creates a static DependencyHelperthat doesn't take into account the possibility of needing this helper with different entity types and bundles in one request. I'll leave a comment on the other issue.

nuez’s picture

It looks like the same tests are failing as on https://www.drupal.org/project/conditional_fields/issues/1161314#comment..., so possibly unrelated.

nuez’s picture

mparker17’s picture

Component: Javascript » Compatibility w/ other modules
Issue summary: View changes
Status: Needs review » Needs work

Updated issue summary and some issue metadata.

The patch in #27 does inject information about the inner form's entity so that it can be detected when conditional_fields_element_after_build() runs for the outer form, by attaching the entity type ID, bundle ID and field name inside conditional_fields_field_widget_form_alter(); as well as making sure that the conditional_fields_element_after_build() function is attached to the element, not the form.

The result is that both conditional_fields.js and the drupalSettings snippet are added to the outer form. However, the patch in #27 doesn't work using the steps to reproduce in the issue summary, because the drupalSettings snippet specifies an HTML ID that would be valid for the inner form, but is not valid once that inner form is injected into the outer form by IEF. That is to say, using the steps to reproduce, the drupalSettings snippet is...

"conditionalFields": {
  "effects": {
    "#edit-field-related-article-wrapper": []
  }
},

... but the image field wrapper inside the inline entity form has the HTML ID... #edit-field-related-article-0-inline-entity-form-field-image-wrapper, so the code in conditional_fields.js does not run.

The patch in #27 also appears to contain some media-entity-specific code...

    /**
     * @deprecated Not actual from Drupal 8.7.0.
     * Media entity returns the actual bundle object, rather than id
     */
    if (is_object($bundle) && method_exists($bundle, 'getPluginId')) {
      $bundle = $bundle->getPluginId();
    }

... which we should re-evaluate for 8.9.0 and/or make more universal.

So I'm setting the issue to "needs work".

alegacy99’s picture

Is there any patch that works for 8.9.2 available? Tried #30 but fails.

NightAr’s picture

Assigned: Unassigned » NightAr
NightAr’s picture

Status: Needs work » Needs review
FileSize
41.65 KB

I had made some changes in the patch, actuality I got the bundle and entity_type data from the "Inline Entity Field" module.

Also, when we got the states of the fields, I got the components from the EntityFormDisplay object, which I got from the entity object stored by the "Inline Entity Field" module.

djdevin’s picture

I tested #33 and visually it worked! But on form submit (the form containing the IEF) I got an error. I can't investigate it right now so here it is. Basic conditionals were set up (checkbox on a text field).

The website encountered an unexpected error. Please try again later.
TypeError: Argument 2 passed to Drupal\Component\Utility\NestedArray::getValue() must be of the type array, null given, called in /xxx/conditional_fields/src/ConditionalFieldsFormHelper.php on line 627 in Drupal\Component\Utility\NestedArray::getValue() (line 69 of core/lib/Drupal/Component/Utility/NestedArray.php).

Drupal\Component\Utility\NestedArray::getValue(Array, NULL) (Line: 627)
Drupal\conditional_fields\ConditionalFieldsFormHelper::formFieldGetValues(NULL, Object) (Line: 564)
Drupal\conditional_fields\ConditionalFieldsFormHelper::formValidate(Array, Object)
call_user_func_array(Array, Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 273)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'course_course_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('course_course_form', Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('course_course_form', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
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: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
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: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
NightAr’s picture

I had update the patch.

djdevin’s picture

I tested this, the fields now show/hide and save correctly.

Unfortunately it does not seem to work with conditionally required/optional fields, but I believe that may be an existing issue with conditional fields outside of this patch. A required field is still required if it is hidden conditionally.

NightAr’s picture

Assigned: NightAr » Unassigned

As I see, the issue with the required field in the hidden state already exists - https://www.drupal.org/project/conditional_fields/issues/2845855.
I guess it should be updated.

darrenwh’s picture

I've just done a clean install of D9 and the issue is no longer replicable.

Screen recording

I wonder if a change in this core resolves this issue?

Will retest with latest version of 8.9

darrenwh’s picture

I have installed a boilerplate version of Drupal 8.9.7 on docksal.
Installed and enabled both of the above modules.
Have same result as above, so cant replicate issue.

I have not tested the scenario mentioned in #36

Can anyone replicate this in the current version of Drupal?

darrenwh’s picture

Reading the replication steps, step 8 says to go to node/add/page this is what I have done, but reading more of the issue it seems to be more related to embedded entities that have the same fields where the issue is, my bad. Will look at the final task...

darrenwh’s picture

@djdevin I have tested the latest patch in the scenario mentioned, discounting my comments in 38 ad 39, and I still see the issue with the conditional action not working inside of the inline entity on a CT. on your comment on 36 you say you have tested and it works?

hedge89’s picture

[@nightar] your patch works for me, but only for the first layer of IEF. We have IEF within IEF and it doesn't work below the first level.

My company are looking to pay for someone to complete this work and get the fix committed, is anyone who is familiar with the issue available?

vselivanov’s picture

Patch #35 doesn't work for multiple entity reference field with IEF (both Simple and Complex widget types).
You can create/edit the 1st node with IEF, but will get the error with the 2nd one.

ChrisDarke’s picture

Would be great if this patch supported other EntityForm types, and as such if instead of enforcing instanceof NodeForm in getFieldFormDisplay, it instead checked against ContentEntityForm. I am currently testing this approach as my use case is not with a NodeForm, but if anyone knows of other issues this may bring up, do give me a shout... also going to be looking into the other issues around the multiple IEF.

colan’s picture

Issue summary: View changes

As #1161314: Add basic Field Group support for ANDing conditions is now in, this may need to be re-rolled.

Someone mentioned over there that it will be necessary to statically cache DependencyHelper for different entity types / bundles. The details are at #1161314-235: Add basic Field Group support for ANDing conditions, and I added this to the remaining tasks in the IS here. Please remove it if that's now out-of-date, or something.

ChrisDarke’s picture

Rerolled that patch with a couple of tweaks in this fork:

https://git.drupalcode.org/issue/conditional_fields-2856720/-/tree/28567...

Dave Kopecek’s picture

#46 Works for me when patched against 48b240345

nonom’s picture

This project is no longer maintained?

lmingarro’s picture

I reproduce the error using

  • D8.9.13
  • Inline Entity Form 8.x-1.0-rc8
  • Conditional Fields 1.x-dev

And changed the widget from the default to Inline entity form - Complex not simple as the description saids.

Then I fetched the issue fork conditional_fields-2856720 and the error was fixed. I'm not sure which patch was applied to the fork but now the bug is fixed.

I'm not sure if this is enough but I changed the status of the issue

lmingarro’s picture

Status: Needs review » Reviewed & tested by the community
SocialNicheGuru’s picture

If I use a non-default form mode t display IEF, would this issue help, https://www.drupal.org/project/conditional_fields/issues/3063330

SocialNicheGuru’s picture

also this does not apply for me anymore

SocialNicheGuru’s picture

Status: Reviewed & tested by the community » Needs work
lmingarro’s picture

lexsoft’s picture

Drupal Version
8.9.13

51 patch applies for me on "drupal/conditional_fields": "1.x-dev#5ae3db4b5497d5ea487a0d6cc9ee1f5ddf9c931f"

But the required condition does not work on inline entity form. Visible and invisible for fields works.

lexsoft’s picture

Version: 8.x-1.x-dev » 4.x-dev
lexsoft’s picture

It would be really useful if we can get this in 4.x .

Anilu@’s picture

Intalling patch #51 with composer did not work

Drupal core 9.3.9

Composer.json

"drupal/conditional_fields": {
"Support for Inline Entity Form": "https://www.drupal.org/files/issues/2020-05-15/2856720-51.patch"
}

❯ composer install
Gathering patches for root package.
Removing package drupal/conditional_fields so that it can be re-installed and re-patched.
- Removing drupal/conditional_fields (4.0.0-alpha1)
Deleting web/modules/composer/conditional_fields - deleted
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update
`.
Package operations: 1 install, 0 updates, 0 removals
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
- Installing drupal/conditional_fields (4.0.0-alpha1): Extracting archive
- Applying patches for drupal/conditional_fields
https://www.drupal.org/files/issues/2020-05-15/2856720-51.patch (Support for Inline Entity Form)
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-05-15/2856720-51.patch

In Patches.php line 326:

Cannot apply patch Support for Inline Entity Form (https://www.drupal.org/files/issues/2020-05-15/2856720-27.patch)!

Anilu@’s picture

I tried #52 related issue solution and did not work with Drupal core 9.3.9

Murz made their first commit to this issue’s fork.

Murz’s picture

I've re-rolled patch from #51 on last 4.x-dev version in a new branch: https://git.drupalcode.org/issue/conditional_fields-2856720/-/compare/4....
but it doesn't work properly, seems too many changes were happened in the module.

So I've started from scratch in this branch: https://git.drupalcode.org/issue/conditional_fields-2856720/-/tree/28567...

Murz’s picture

Assigned: Unassigned » Murz
Status: Needs work » Needs review

I've created a new implementation of the functional for adding support of inline_entity_form to the Conditional Fields module in the https://git.drupalcode.org/project/conditional_fields/-/merge_requests/16#note_92767 - can anybody please review and test it?

In this implementation I'm checking all parents of the element, and if found parent with id inline_entity_form - I'm extracting this subform as separate form, getting $entity_type and $bundle from it, and removing all parents upper than inline entity form.

After that I'm passing the data to further processing without changes.

Also I've got a problem with case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET - it works wrong for me in all cases, so I've changed the logic to fix it. Hope this fix doesn't broke any other widget types.

Please test and review my implementation and leave comments if anything needs rework, or something goes broken.

jwilson3’s picture

latest MR doesn't apply to 4.0.0@alpha but works fine for my use case:

composer require drupal/conditional_fields:dev-4.x

Haven't had a chance to review the code changes in detail, so I apologize that cannot really give any feedback at the moment.

lexsoft’s picture

This patch is the merge work done by @Murz plus 1 commit from myself.
Should apply to latest dev:
"drupal/conditional_fields": "4.x-dev@dev"

Status: Needs review » Needs work

The last submitted patch, 66: support-for-inline-entity-form-2856720-66.patch, failed testing. View results

lexsoft’s picture

lexsoft’s picture

Status: Needs work » Needs review
Selphie’s picture

Assigned: Murz » Unassigned

I tried the patch from #68 with Drupal 9.5 and conditional fields 4.x-dev and it is not working in my case.
If I edit Entity A directly, it is working. If I edit Entity B having an entity reference on Entity A via Inline Entity Form, it throws wsod.

I got the following error report:

Warning: Undefined array key "#field_parents" in Drupal\conditional_fields\ConditionalFieldsFormHelper->getState() (line 287 of /var/www/html/am_wisski/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php)

#0 /var/www/html/am_wisski/core/includes/bootstrap.inc(347): _drupal_error_handler_real()
#1 /var/www/html/am_wisski/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php(287): _drupal_error_handler()
#2 /var/www/html/am_wisski/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php(199): Drupal\conditional_fields\ConditionalFieldsFormHelper->getState()
#3 /var/www/html/am_wisski/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php(122): Drupal\conditional_fields\ConditionalFieldsFormHelper->processDependeeFields()
#4 /var/www/html/am_wisski/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php(96): Drupal\conditional_fields\ConditionalFieldsFormHelper->processDependentFields()
#5 /var/www/html/am_wisski/modules/contrib/conditional_fields/conditional_fields.module(201): Drupal\conditional_fields\ConditionalFieldsFormHelper->afterBuild()
#6 [internal function]: conditional_fields_form_after_build()
#7 /var/www/html/am_wisski/core/lib/Drupal/Core/Form/FormBuilder.php(1078): call_user_func_array()
#8 /var/www/html/am_wisski/core/lib/Drupal/Core/Form/FormBuilder.php(1070): Drupal\Core\Form\FormBuilder->doBuildForm()
#9 /var/www/html/am_wisski/core/lib/Drupal/Core/Form/FormBuilder.php(1070): Drupal\Core\Form\FormBuilder->doBuildForm()
#10 /var/www/html/am_wisski/core/lib/Drupal/Core/Form/FormBuilder.php(1070): Drupal\Core\Form\FormBuilder->doBuildForm()
#11 /var/www/html/am_wisski/core/lib/Drupal/Core/Form/FormBuilder.php(1070): Drupal\Core\Form\FormBuilder->doBuildForm()
#12 /var/www/html/am_wisski/core/lib/Drupal/Core/Form/FormBuilder.php(444): Drupal\Core\Form\FormBuilder->doBuildForm()
#13 /var/www/html/am_wisski/core/lib/Drupal/Core/Form/FormBuilder.php(628): Drupal\Core\Form\FormBuilder->rebuildForm()
#14 /var/www/html/am_wisski/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\Core\Form\FormBuilder->processForm()
#15 /var/www/html/am_wisski/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(48): Drupal\Core\Form\FormBuilder->buildForm()
#16 /var/www/html/am_wisski/modules/contrib/wisski/wisski_core/src/Controller/WisskiEntityController.php(100): Drupal\Core\Entity\EntityFormBuilder->getForm()
#17 [internal function]: Drupal\wisski_core\Controller\WisskiEntityController->add()
#18 /var/www/html/am_wisski/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#19 /var/www/html/am_wisski/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#20 /var/www/html/am_wisski/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#21 /var/www/html/am_wisski/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#22 /var/www/html/am_wisski/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#23 /var/www/html/am_wisski/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#24 /var/www/html/am_wisski/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#25 /var/www/html/am_wisski/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#26 /var/www/html/am_wisski/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#27 /var/www/html/am_wisski/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#28 /var/www/html/am_wisski/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#29 /var/www/html/am_wisski/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#30 /var/www/html/am_wisski/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#31 /var/www/html/am_wisski/core/lib/Drupal/Core/DrupalKernel.php(702): Stack\StackedHttpKernel->handle()
#32 /var/www/html/am_wisski/index.php(18): Drupal\Core\DrupalKernel->handle()
#33 {main}

I tried to debug and there indeed seems to be no "#field_parents" in the dumped data (DANGER: serialized!):
a:30:{s:5:"#type";s:5:"radio";s:6:"#title";O:37:"Drupal\Core\Field\FieldFilteredMarkup":1:{s:9:"*string";s:5:"Video";}s:13:"#return_value";s:5:"Video";s:14:"#default_value";b:0;s:11:"#attributes";a:1:{s:20:"data-drupal-selector";s:95:"edit-f827b9aabd816f689787eae1e49679f6-form-0-fd9217b12dea6e4c8e294f0c312b541a-video-d82wdgyd4fa";}s:8:"#parents";a:4:{i:0;s:32:"f827b9aabd816f689787eae1e49679f6";i:1;s:4:"form";i:2;i:0;i:3;s:32:"fd9217b12dea6e4c8e294f0c312b541a";}s:3:"#id";s:96:"edit-f827b9aabd816f689787eae1e49679f6-form-0-fd9217b12dea6e4c8e294f0c312b541a-video--D82wdgYd4FA";s:5:"#ajax";N;s:17:"#error_no_message";b:1;s:7:"#weight";d:0.001;s:6:"#input";b:1;s:8:"#process";a:1:{i:0;a:2:{i:0;s:32:"Drupal\Core\Render\Element\Radio";i:1;s:15:"processAjaxForm";}}s:11:"#pre_render";a:1:{i:0;a:2:{i:0;s:32:"Drupal\Core\Render\Element\Radio";i:1;s:14:"preRenderRadio";}}s:6:"#theme";s:12:"input__radio";s:15:"#theme_wrappers";a:1:{i:0;s:12:"form_element";}s:14:"#title_display";s:5:"after";s:15:"#value_callback";a:2:{i:0;s:32:"Drupal\Core\Render\Element\Radio";i:1;s:13:"valueCallback";}s:12:"#after_build";a:1:{i:0;s:38:"conditional_fields_element_after_build";}s:16:"#defaults_loaded";b:1;s:5:"#tree";b:1;s:14:"#array_parents";a:7:{i:0;s:32:"f827b9aabd816f689787eae1e49679f6";i:1;s:6:"widget";i:2;s:4:"form";i:3;s:18:"inline_entity_form";i:4;s:32:"fd9217b12dea6e4c8e294f0c312b541a";i:5;s:6:"widget";i:6;s:5:"Video";}s:10:"#processed";b:1;s:9:"#required";b:0;s:20:"#description_display";s:5:"after";s:7:"#errors";N;s:5:"#name";s:75:"f827b9aabd816f689787eae1e49679f6[form][0][fd9217b12dea6e4c8e294f0c312b541a]";s:6:"#value";b:0;s:15:"#ajax_processed";b:0;s:7:"#sorted";b:1;s:17:"#after_build_done";b:1;}

Thank you for your help!

B1’s picture

Drupal 9.4
PHP 8.1.7
Conditional fields: 4.x-dev@dev
Inline entity form:1.0@RC

Add a conditional field to an inline entity form.

Condition is ignored.

Apply Patch by lexsoft (comment #69)

Condition successful.

Unsure why Selphie (comment #70) got WSOD, perhaps a version of Video Module might cause conflict?

If someone else tests
support-for-inline-entity-form-2856720-67.patch , then perhaps we can move forward.

Vladimir Tanovic’s picture

Added a patch for notice @Selphie got, I had the same issue.

One big notice, this patch does not work with the latest alpha version.

Vladimir Tanovic’s picture

Hm, patch failed to apply but it did applied successfully on my side

nevergone’s picture

Re-rolled #2856720-73: Support for Inline Entity Form patch, base commit: b7dd4872a61c06f040b7a0997e044b9ad50136d0

Please check the re-rolling, manual fixing this patch.

Vladimir Tanovic’s picture

Yep, thanks @nevergone, this should resolve the warning and notice on patch #68 for dev version.

There still needs to be created a patch for alpha version though.

nevergone’s picture

@Vladimir Tanovic:

Why? Why is there no new (alpha, beta) release?

riazsaid15’s picture

When I apply the #74 patch then the below error comes in when I create a new node.
InvalidArgumentException: Missing required properties for an EntityDisplay entity. in Drupal\Core\Entity\EntityDisplayBase->__construct().

When I change the inline form entity from simple to complex then this error removes and conditional field logic is not working. Any idea why this error is coming?

Rajab Natshah’s picture

On editing IEF
I'm facing the same issue "Missing required properties for an EntityDisplay entity."

Rajab Natshah’s picture

Found 2 issues in the patch
Using PHP 8.0 and PHP 8.1
1st one

  • The $widget_id will not have a value. As it's in conditions .. needed $widget_id = '';

2nd one

  • When checked $dependee_form_field['#entity_type'] it's empty .. I'm using paragraphs in my case
  • When checked the $dependee_form_field['#bundle'] it is empty too. I'm using a doc bundle for paragraphs

The following change over the getState method, will have it work in both simple and complex IEF

Not sure in which hook it should pass the #entity_type and #bundle
Maybe the entity reference field should pass them in the other hook options.

This is a static fix ( using it as a local patch fix) , which should not be used as a general fix .. it's only for paragraphs and a paragraph type called doc

More generic fix should be changed in the MR or patch

  protected function getState($dependee, array $dependee_form_field, array $options) {
    /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
    $form_display = $this->form_state->getFormObject()->getFormDisplay($this->form_state);
    $state = [];

    if ($options['condition'] != 'value') {
      // Conditions different than "value" are always evaluated against TRUE.
      $state = [$options['state'] => [$options['selector'] => [$options['condition'] => TRUE]]];
    }
    else {
      $widget_id = '';

      $field_name = explode('[', $dependee_form_field['#name']);
      $dependee_form_state = isset($dependee_form_field['#field_parents'], $field_name[0], $this->form_state) ? WidgetBase::getWidgetState($dependee_form_field['#field_parents'], $field_name[0], $this->form_state) : NULL;
      $dependee_form_field['#original_name'] = $field_name[0];
      $dependee_display = $form_display->getComponent($dependee);
      if (is_array($dependee_display) && array_key_exists('type', $dependee_display)) {
        $widget_id = $dependee_display['type'];
      }

      // If inline entity form is used, pass the form mode for getFormDisplay
      // and get the widget ID from field.
      if ($widget_id == '' && in_array('inline_entity_form', $dependee_form_field['#field_parents'])) {

        $ief = $form_display->getComponent($dependee_form_field['#field_parents'][0]);

        $dependee_form_field['#entity_type'] = 'paragraph';
        $dependee_form_field['#bundle'] = 'doc';

        $ief_form_display = $this->entityDisplayRepository->getFormDisplay($dependee_form_field['#entity_type'], $dependee_form_field['#bundle'], $ief['settings']['form_mode']);
        $ief_dependee_display = $ief_form_display->getComponent($dependee);
        if (is_array($ief_dependee_display) && array_key_exists('type', $ief_dependee_display)) {
          $widget_id = $ief_dependee_display['type'];
        }
      }

      // @todo Use field cardinality instead of number of values that was
      // selected on manage dependency tab. As temporary solution put
      // cardinality in $options. Format of #states depend on field widget and
      // field cardinality (it can be like value: string and value: [array]).
      if ($field_config = FieldStorageConfig::loadByName($form_display->getTargetEntityTypeId(), $dependee)) {
        $options['field_cardinality'] = $field_config->getCardinality();
      }

      // Execute special handler for fields that need further processing.
      // The handler has no return value. Modify the $state parameter by
      // reference if needed.
      if (isset($widget_id)) {
        $handler_id = 'states_handler_' . $widget_id;
        /** @var Drupal\conditional_fields\ConditionalFieldsHandlersPluginInterface $handler */
        $handler = $this->type->createInstance($handler_id);
        $state = $handler->statesHandler($dependee_form_field, $dependee_form_state, $options);
      }

      if (empty($state)) {
        // If states empty Default plugin.
        /** @var Drupal\conditional_fields\ConditionalFieldsHandlersPluginInterface $default_handler */
        $default_handler = $this->type->createInstance('states_handler_default_state');
        $state = $default_handler->statesHandler($dependee_form_field, $dependee_form_state, $options);
      }
    }

    return $state;
  }

Maybe a further checks over if the IEF module was enabled and used in the entity reference field widget

saurabh-2k17’s picture

Hi, I have updated the patch with the changes from #74 and #79 including few other changes to make it work.
Please find patch and interdiff attached, Thanks

Status: Needs review » Needs work

The last submitted patch, 80: 2856720-support_for_inline_entity_form-80.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

saurabh-2k17’s picture

Assigned: saurabh-2k17 » Unassigned
Status: Needs work » Needs review
saurabh-2k17’s picture

Hi, I updated the patch with some changes.

welly’s picture

I don't know if it's related to the patch but I'm getting the following error when I applied it.

TypeError: Drupal\conditional_fields\ConditionalFieldsFormHelper::elementAddProperty(): Argument #1 ($element) must be of type array, null given, called in /var/www/html/web/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php on line 208 in Drupal\conditional_fields\ConditionalFieldsFormHelper->elementAddProperty() (line 888 of modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php).
welly’s picture

Status: Needs review » Needs work
ramil g’s picture

Here's a re-roll of patch #83 for the latest 4.0.0-alpha5 release.

ramil g’s picture

Just uploading another patch that fixes a part in afterbuild where it wasn't getting the right entity bundle.

Does this patch work for anybody out there? It's currently not working for us, and we're working on getting it to work. Just curious if there's anyone out there that this patch is working for.

joelpittet’s picture

Just for context on the above interdiff in #87.

-          $bundle = $form['#bundle'] ?? FALSE;
-          $entity_type = $form['#entity_type'] ?? FALSE;
+          $ief_entity = $form["#entity"];
+          $bundle = $ief_entity->bundle();
+          $entity_type = $ief_entity->getEntityTypeId();

Our $form['#bundle'] was null and thus FALSE. This is for a custom entity type. Grabbing it from the $form["#entity"] gave it the right value (as is similar but not the same to the current code outside of IEF).

We are playing with the idea of simplifying the code paths be removing:

-    $form = &$form_state->getCompleteForm();
+    $full_form = &$form_state->getCompleteForm();

And letting the $form variable be unchanged.

and

   public function loadDependencies($entity_type, $bundle) {
-    static $dependency_helper;
-    if (!isset($dependency_helper[$entity_type][$bundle])) {
-      $dependency_helper[$entity_type][$bundle] = new DependencyHelper($entity_type, $bundle);
+    static $dependency_helpers;
+    $dependency_key = $entity_type . '.' . $bundle;
+    if (!isset($dependency_helpers[$dependency_key])) {
+      $dependency_helpers[$dependency_key] = new DependencyHelper($entity_type, $bundle);
     }
-    return $dependency_helper[$entity_type][$bundle]->getBundleDependencies();
+    return $dependency_helpers[$dependency_key]->getBundleDependencies();
   }

Looks to be unneeded since the reroll in #86.

ramil g’s picture

This patch gets it working for us.
Inside the getState method of ConditionalFieldsFormHelper, when you use $form_state to grab the entity , it gives you the entity from the main form, rather than the entity inside the inline entity form (the entity being referenced). This patch fixes that.

ramil g’s picture

Status: Needs work » Needs review
Megha_kundar’s picture

Status: Needs review » Reviewed & tested by the community

Working as expected
Thank you very much for patch !!
Hence moving to RTBC.

very_random_man’s picture

Status: Reviewed & tested by the community » Needs work

This patch in #89 causes the following error when trying to use Config Split to edit a config split setting.

Error: Call to a member function bundle() on null in Drupal\conditional_fields\ConditionalFieldsElementAlterHelper->afterBuild() (line 64 of modules/contrib/conditional_fields/src/ConditionalFieldsElementAlterHelper.php).

Removing the patch allows it to work.

joelpittet’s picture

@very_random_man maybe you can provide more info? We use config_split also. What version and what config was being split? Maybe we can reproduce the error and fix it. Thabks

very_random_man’s picture

Apologies for the terse response. :-)

I'm not sure it's specific to the config. I get the error when just trying to edit the config split entity at /admin/config/development/configuration/config-split/[ id ]/edit

I'm using Config Split 1.9.0 on Drupal 10.2.1.

This is the complete backtrace:

Error: Call to a member function bundle() on null in Drupal\conditional_fields\ConditionalFieldsElementAlterHelper->afterBuild() (line 64 of modules/contrib/conditional_fields/src/ConditionalFieldsElementAlterHelper.php).
conditional_fields_element_after_build(Array, Object)
call_user_func_array('conditional_fields_element_after_build', Array) (Line: 1084)
Drupal\Core\Form\FormBuilder->doBuildForm('config_split_edit_form', Array, Object) (Line: 1076)
Drupal\Core\Form\FormBuilder->doBuildForm('config_split_edit_form', Array, Object) (Line: 1076)
Drupal\Core\Form\FormBuilder->doBuildForm('config_split_edit_form', Array, Object) (Line: 1076)
Drupal\Core\Form\FormBuilder->doBuildForm('config_split_edit_form', Array, Object) (Line: 579)
Drupal\Core\Form\FormBuilder->processForm('config_split_edit_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Having now had a look in the code, it looks like the `findInlineEntityFormParentsForElement` method is getting confused and incorrectly identifying a checkbox element instead of an inline_entity_form on the basis that it is called 'inline_entity_form'. I would assume that this is because the config split form has a checkboxes for each module.

I think the solution would be to check to see if the parent IEF form is actually a form and not a form element as part of `findInlineEntityFormParentsForElement`, rather than just assuming that is only IEF forms are called 'inline_entity_form'.

ramil g’s picture

Thanks for reporting this @very_random_man and thanks for that info. I think you're right, it does need a check to make sure it's an inline entity form. We've implemented this in this new patch.

very_random_man’s picture

Status: Needs work » Reviewed & tested by the community

Nice one, thanks! That definitely does the job. :-)

dqd’s picture

What a long issue and patch history! +1 for all the hard work in here.

Review/Testing now for commit ...

dqd’s picture

But we need some polish of the issue before commiting:

If the support of IEF has been assumed before in the project but needed fixes to work properly then this is a bug, yes, but if this hasn't been a documented feature yet in there before, it should be changed to Feature request for better tracking regarding change record details for a next release. Especially because this patch involves a lot of changes and additions.

IMHO, I rather consider this here Feature request, but, if this keeps being a bug for reasons, then the title is too random.

The summary part:

Proposed resolution

Inject information about the inner form's entity so that it can be detected when conditional_fields_element_after_build() runs for the outer form.

.. seems still valid in a certain way but the patch history kindof changed/increased the radius of the scope a little, so we need to change the title accordingly before commiting this change, since the original title is too random to track down possible follow ups. Thoughts for a better title from the latest patch authors?

We have
+ * Implements hook_inline_entity_form_entity_form_alter().
and
+ // Detect if this element is located inside inline_entity_form.
and namespace additions like

+use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
+use Drupal\Core\Entity\EntityFormInterface

Again, to summarize: If this keeps being a "Bug" then we need a title better reflecting the fixes implemented. If we turn it into a "Feature request" - what I would recommend TBH - then the title is OK, because it is the issue where the final implementation of IEF support has been done.

dqd’s picture

Hm ... to speed things up here (this issue has run long enough) I take my own consideration into account. Especially because

When an inline entity form is used to create content, the conditional_field.js is not loaded and the conditional field rules do not run.

clearly states that IEF hasn't been supported yet before. And I do not see any documented support for IEF in this project before mentioned. I will set this issue to FR now.

But I see a lot of issues with the same scope not linked here yet, like:

Some of them I will surely close in favour of this one here.

  • dqd committed 7ec4b704 on 4.x authored by ramil g
    Issue #2856720 by Murz, ramil g, lexsoft, ChrisDarke, saurabh-2k17,...
dqd’s picture

Status: Reviewed & tested by the community » Fixed

  • dqd committed f988abcf on 4.x
    Remove patch file accidently left in file tree from issue #2856720.
    
dqd’s picture

Addendum: Removed patch file accidently left in file root from latest commit. Too many terminals open today to clean up the issue queue...

Status: Fixed » Closed (fixed)

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