Problem/Motivation

Provide hooks for modules to react when inline entities are saved or deleted and open the way to easily integrate IEF in complex environments, when using contrib modules for content access and permission handling(e.g. Group module).
This feature was already requested several times and requires only minor modifications:
#2976376: Inline editing in the group context
#3190079: IEF and Group integration
#3144853: Group and IEF Integration

Proposed resolution

Provide three new hooks for modules to react on:

  • after an inline entity is saved
  • before an entity is deleted
  • after the create bundles list is populated

Remaining tasks

Create a patch

User interface changes

None

API changes

Yes

Data model changes

None

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

JordiK created an issue. See original summary.

jordik’s picture

jordik’s picture

Status: Active » Needs review

The patch above adds three new hooks to the IEF API :

  • hook_inline_entity_form_entity_save - react after the inline entity is saved, distinguish if the entity is created or updated, without modifying it
  • hook_inline_entity_form_entity_delete - react before the inline entity is deleted, without modifying it
  • hook_inline_entity_form_create_bundles_alter - give the possibility to modify the list of entity bundles, which can be created in the IEF widget.
jordik’s picture

StatusFileSize
new4.36 KB

Add the inline_entity_form widget to the context.

jordik’s picture

StatusFileSize
new4.46 KB

Re-roll of patch from #4 to latest dev (Apr 15 2021, rc9).
Needs review.

rp7’s picture

Sounds like a good idea IMO. Thank you.

Two questions:

  • What do you exactly mean with without modifying it?
  • Can we add these hooks to the simple widget as well?
jordik’s picture

What do you exactly mean with without modifying it?

This means that one can not modify the entity object in the hook, only the $form_state object.

Can we add these hooks to the simple widget as well?

Yes, but it is up to the maintainers to decide this.

odai atieh’s picture

StatusFileSize
new4.46 KB

I updated the latest patch to fix the warning ($form_state) must be passed by reference.

  • podarok committed 24227385 on 2.0.x authored by Odai Atieh
    Issue #3197629 by JordiK, Odai Atieh: New API hooks to react on inline...
podarok’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Status: Needs review » Fixed

#8 is in
tnx

Status: Fixed » Closed (fixed)

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

geek-merlin’s picture

Version: 2.0.x-dev » 3.0.0-rc15
Status: Closed (fixed) » Needs review
Related issues: +#3401656: Clean up problematic 2.x branch

Bulk reopen.

geek-merlin’s picture

Short review: I like the idea, but this needs some work. If someone is still wanting to work on this, i can give a full review.

geek-merlin’s picture

Version: 3.0.0-rc15 » 3.x-dev
jordik’s picture

I can work on this.

jordik’s picture

StatusFileSize
new5.92 KB

Re-rolled the patch for 3.x.-dev.
There was a change in the function determineBundle introduced in #3358281: Wrong bundle form is displayed if user has permissions to create only one of the available bundles.
It is now using $this->getCreateBundles() instead of $this->getTargetBundles() to solve the issue of user permissions to create certain bundles to be respected. Passed $context as variable to the function to allow for the API call.
Works now as expected. Please review.

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

hocu’s picture

You are lifesavers!

I tested the inline_entity_form_entity_save hook so far, and everything works great. I took the liberty of creating an issue fork, just to clean up some warnings raised by PhpStorm (nitpicking mode on 🙄).

Once I test the other hooks, I will update the status to RTBC.

hocu’s picture

Status: Needs review » Reviewed & tested by the community

Tested with latest D10.4. All good, thank you. Converting to RTBC now.