It would be nice to control the form mode for a referenced entity.

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:

Comments

Erik Seifert created an issue. See original summary.

erik seifert’s picture

StatusFileSize
new6.13 KB
erik seifert’s picture

StatusFileSize
new5.22 KB

Without commented code

erik seifert’s picture

StatusFileSize
new5.24 KB

- add comments for function calls
- switch to human readable names in widget

erik seifert’s picture

StatusFileSize
new6.87 KB

- add the possibility for inheritance from a inline_entity_form widget

erik seifert’s picture

StatusFileSize
new7.18 KB

#5 do not really work. Should be more work or a different feature request.

Add new patch.

- Do respect form mode route parameter in entity_browser_form_alter

erik seifert’s picture

StatusFileSize
new7.18 KB
chr.fritsch’s picture

Status: Active » Needs review

Lets trigger testbot

The last submitted patch, 6: 2821917-support-form-mode.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 7: 2821917-support-form-mode.patch, failed testing.

jazzdrive3’s picture

Is this issue about setting the form display mode when someone clicks the edit button?

Right now, it looks like it always just used the "default" form mode, even if you have selected a form mode for adding the entity. Is this the problem this issue addresses?

gge’s picture

I tried #7 with 8.x-2.0-alpha2+2-dev and the patch apply and works nicely. It still needs a bit of polish, like adding an explanation (label) to the select input. This feature makes Entity Browser even more helpful and I hope it gets committed.
Thanks!

recrit’s picture

This patch is confusing the display form mode (configurable in the field ui) with the form classes defined in the entity type.

// The getFormObject() is expecting $form_mode to be the entity form class.
$form_object = $this->entityTypeManager()->getFormObject($entity->getEntityTypeId(), $form_mode);


// And the hook could override a valid form class defined if a form mode had the same name.
function entity_browser_entity_type_build(array &$entity_types) {
  ...
 // $key is the form mode here, $class is the default "edit" form class.
  $entity_types[$mode['targetEntityType']]->setFormClass($key, $class);

It should build the form using the form display object where the mode should default to "default". The paragraphs widget does a similar edit form build for its subform.

  use Drupal\Core\Entity\Entity\EntityFormDisplay;
...
  $display = EntityFormDisplay::collectRenderDisplay($paragraphs_entity, $this->getSetting('form_display_mode'));
... 
  $display->buildForm($paragraphs_entity, $element['subform'], $form_state);
mtalt’s picture

StatusFileSize
new6.64 KB

Re-rolling patch to work with 1.6.

mtalt’s picture

StatusFileSize
new6.68 KB

The user registration form was not working because the register form class was being set to NULL. This checks that the 'edit' form class exists on the entity before modifying the form class.

afi13’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 15: 2821917-15-support-form-mode.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

hawkeye.twolf’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
StatusFileSize
new8.67 KB

Re-rolled to latest 8.x-2.x. Also, I replaced a static conditional in the widget settings form with a States API show/hide.

hawkeye.twolf’s picture

StatusFileSize
new9.52 KB

Adds missing schema for the new setting.

hawkeye.twolf’s picture

StatusFileSize
new9.97 KB

Adds form mode to settings summary.

silverham’s picture

Any reason why this issue has stopped?

silverham’s picture

Theme around attached if anyone is interested.

Dave Reid made their first commit to this issue’s fork.

dave reid’s picture

I opened a PR branch for this feature. We found a couple of issues using the latest version:

1. The #states information was hard-coded to a specific field name. This fixes it to work for all field names by dynamically generating the state information.
2. I added a canUseEditButton() method rather than hard-coding around file entity. This returns FALSE by default for file entities.
3. Injected the service to get the list of form modes rather than using \Drupal in a class.
4. Fixes the widget settings summary to show the edit mode label rather than the raw value, matching the 'View mode' summary.

dave reid’s picture

Status: Needs work » Needs review

The last submitted patch, 19: 2821917-19-support-form-mode.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dave reid’s picture

StatusFileSize
new26.67 KB

Latest version based on the merge request, still need to work on fixing the tests but this seems to work correctly.

Status: Needs review » Needs work

The last submitted patch, 28: 2821917-support-form-mode.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

hawkeye.twolf’s picture

I haven't dug into why yet, but just noting the patch doesn't seem to work for on the relatively vanilla D9 site I just tried it on. Applies cleanly and the new field widget configuration gets saved correctly, but the form mode doesn't seem to change. I'll probably be coming back to this at some point to investigate further.

jberube’s picture

The patch from #28 works for me. I feel it's very important that the edit button honors the desired form mode. I'd really like to see this patch merged in.

pierrepaul’s picture

Patch #28 is also working fine for me. Let me know if I can help with the tests.

gaydamaka’s picture

dave reid’s picture

Status: Needs work » Needs review
StatusFileSize
new27.47 KB

Updated patch against 8.x-2.8.

dave reid’s picture

StatusFileSize
new27.39 KB

Updated patch from MR to remove EntityReferenceBrowserWidget::__construct() now that it's no longer needed.

The last submitted patch, 34: 2821917-support-form-mode.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 35: 2821917-support-form-mode.patch, failed testing. View results

dave reid’s picture

I think I've discovered a bug here, that in entity_browser_entity_type_build() we're calling \Drupal::service('entity_display.repository')->getAllFormModes(), which itself will call the entity type build if the cache isn't ready and it becomes a recursive problem I think.

dave reid’s picture

StatusFileSize
new32.07 KB

Re-rolled patch against 8.x-2.8 release.

gaydamaka’s picture

StatusFileSize
new31.77 KB

Hi, 39 is not applied to 2.8 release

penyaskito’s picture

Status: Needs work » Needs review

Marking as NR so the test run. Tested #40 and it applies. Worked well, but wondering if there's some way to use the IEF if that's available for consistency.

The last submitted patch, 39: 2821917-support-form-mode.patch, failed testing. View results

scotwith1t’s picture

StatusFileSize
new48.99 KB

After applying the latest patch here

  • all of the buttons for multi-value fields as well as paragraphs buttons in the form are being placed in the modal's footer
  • I also still see the Published and Menu form components, even though they are moved out of the form in the selected form mode.

form mode selected, shows buttons in modal footer, published and menu settings

dave reid’s picture

@scotwith1t I think the modal buttons issue is a core bug. See #3151534: "Add another item" field button is displayed as a modal action.

dave reid’s picture

I solved why the edit dialog was always using the default form mode and not the configured version, it was the routing definition had it hard-coded to default. Functionality wise this is working again.

dave reid’s picture

Title: Set form mode for edit button » Allow the edit button's form mode to be selected in Entity Browser field widget settings
dave reid’s picture

StatusFileSize
new21.89 KB

Patch version against the latest 2.10 release.

pearls’s picture

Thanks @Dave Reid
#47 worked for me.
+1 for RTBC

pearls’s picture

Update:
Unable to apply patch(#47) when trying to upgrade to .8.2.11 and 8.2.dev.x.3f2260ba

alexander tallqvist’s picture

StatusFileSize
new21.66 KB

Re-rolled the patch for version 8.x-2.11. Seems to be applying / working fine. Running Drupal 10.3.2.

pearls’s picture

Thanks Alexander ,
#50 worked for me. ( version 8.x-2.11 )

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

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

alt.dev made their first commit to this issue’s fork.

alt.dev’s picture

StatusFileSize
new22.53 KB

I re-rolled the MR to the latest version. Attaching the patch that can be applied to the version 2.15.0

stomusic’s picture

StatusFileSize
new15.27 KB

I re-rolled the last patch from #55 to 2.17.0

loze’s picture

I pushed the patch from #56 to the MR branch, so !4 is current again, and added tests. Thanks @stomusic and @alt.dev for the rerolls.

One change to the patch: It built whichever form mode the widget was set to, and the widget's default setting is default, so the edit dialog started building the default form instead of the edit form. On entity types that have both, like nodes, that changes the form ID and any hook_form_FORM_ID_alter() written against the edit form stops running. ParagraphsTest caught it. Now default means no form mode was picked and the old behaviour stays, while a form mode you actually choose is still used. $form_mode also moved after $request and gained a default value, so the controller can still be called with two arguments.

Added tests to EntityBrowserEditFormTest:

  • a chosen form mode is used to build the edit form
  • default still gets the edit form
  • a form mode that no longer exists falls back instead of throwing

CI is green. phpcs, phpstan, eslint, stylelint and cspell fail the same way on 8.x-2.x itself, so they are not from this branch.

miiimooo’s picture

Status: Needs review » Needs work

Patch from #55 with 2.15.0 works for me, and the form mode is used as configured in the modal.

Patch from #55 with 2.16.0 (SECURITY) works for me, and the form mode is used as configured in the modal.

But it lost the default for the `form_mode` in the route declaration for `entity_browser.edit_form`, which breaks other usages:

entity_browser.edit_form:
  path: /entity_browser/{entity_type}/{entity}/edit/{form_mode}
  defaults:
    _controller: '\Drupal\entity_browser\Controllers\EntityBrowserController::entityBrowserEdit'
    form_mode: 'default'

It was removed in #47 but it doesn't seem necessary.

Patch from #56 does not work for me: the default form mode is used instead.

The patch needs re-rolling for the bigger changes in entity_browser 8.x-2.x