I am getting a problem where the widget doesn't render in the field settings form. I am currently using the widget for selecting existing references to a media entity, and when I go into the field settings, the default value does not render at all. I will attach a screenshot. There are no errors in the console nor in the database log.

Currently, in order to change the default value, I have to switch the widget to use a non ief widget, and then switch the widget back after saving. I would appreciate all the help.

Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bobbysaul created an issue. See original summary.

bobbysaul’s picture

I believe the issue is with the canBuildForm function in the InlineEntityFormBase.php.

This needs to be adjusted for the InlineEntityFormComplex if it allows the use of existing entity references.

bobbysaul’s picture

I was able to add the canBuildForm function to the complex widget, and add the check if allowed to use existing nodes.

protected function canBuildForm(FormStateInterface $form_state) {
    if ($this->isDefaultValueWidget($form_state) && !$this->getSetting('allow_existing')) { // check if allowed to use existing
      return FALSE;
    }

    if (!$this->inlineFormHandler) {
      return FALSE;
    }

    return TRUE;
}

The only problem now is the value won't save. The widget will build now. I just need to be able to save the default value selected.

bobbysaul’s picture

The saving problem is fixed by adjusting the extractFormValues function to check if existing nodes are allowed.

if ($this->isDefaultValueWidget($form_state) && !$this->getSetting('allow_existing')) {
     $items->filterEmptyItems();
     return;
}
bobbysaul’s picture

Status: Active » Needs review
neeravbm’s picture

@bobbysaul I am not able to reproduce this issue. When referencing an existing Media content using IEF, I do see an "Add existing media" button. On pressing this button, I get an autocomplete form to reference an existing file/image. It's possible that our settings our different. I have attached images of my configuration below. Can you provide steps to reproduce the issue?

Reference type config

IEF setting

Add existing media button

Add existing media autocomplete textfield

bobbysaul’s picture

@neeravbm, I think that my problem was misunderstood. I am able to get the field to render on the normal form (node/add/test). The problem is that the field does not render on the field settings form when setting the default values (admin/structure/types/manage/test/fields/node.test.field_media).

Here is a screen shot of the widget settings (I have matched the same as you):
Only local images are allowed.

This is a screen shot of the field settings form before the patch (notice the details element labeled 'DEFAULT VALUE'):
Only local images are allowed.

This is a screen shot of the same page after applying the patch (see how the field widget is now nested in the 'DEFAULT VALUE' detail):
Only local images are allowed.

xenophyle’s picture

Thank you very much @bobbysaul. This patch solved this mysterious bug.

gaurav_manerkar’s picture

Can we implement same for Inline form - simple ?

geek-merlin’s picture

Status: Needs review » Needs work
Issue tags: -default value +Needs tests

That one needs a failing test to go in.