Loading "host" entities

Created on 10 January 2024, 6 months ago
Updated 24 January 2024, 5 months ago

Problem/Motivation

I'm using ECK + ECA to create much better interfaces for adding products and Variations in Drupal Commerce. This is usually a multi-step process whereas with ECK it is possible to create interfaces where people can add products and their variations with their stock levels in one GUI. ECA can then create the entities and set their values, as well as relieve people of the burden of dealing with SKUs.

Right now I've added an Inline Entity Form to the standard Commerce Product GUI. Through the IEF, people can create and populate multiple product variations instead of adding them one-by-one after saving the Product entity.

I now have an ECA model that reacts on inserting an ECK entity. But I can't figure out how to load the entity that the ECK product entity is attached to. What I'm looking for is a token like "entity:host" or "entity:parent" or something along those lines. I figure I could accomplish this with a view but wondering if there is a better way of accessing the parent entity of an entity that is created via IEF?

Thanks!

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ’¬ Support request
Status

Fixed

Version

1.1

Component

Documentation

Created by

πŸ‡ΉπŸ‡­Thailand AlfTheCat

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @AlfTheCat
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Moving this away from version 1.2.x as this is not a thing. Current version is 1.1.x and the next version will be 2.0.x, nothing in between. Unfortunately, we can't delete that 1.2.x branch for compliance reason, but please don't use that.

    Your question seems unrelated to ECK. It sounds more generic like you have an entity which has a multi-value reference field to other entities. And you want to know the entity if one of the referenced entities get inserted? That's actually not possible, because when inserting the referenced entities, that get created from the same form as you're using IEF, at that time the parent entity hasn't been saved yet. In such a scenario, Drupal first creates all the referenced entities and afterwards the parent entity. That's necessary, because when saving the parent, the referenced entities must already exist; otherwise Drupal couldn't save the reference to them.

    So, you may have to react on the insert parent entity event, and then go through the list of all the referenced entities to do your magic.

  • Status changed to Fixed 6 months ago
  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    OK, thanks very much for the comprehensive clarification. And I will mind the 1.2.x branch issue. I will go the direction of reacting to the saving of the parent entity and then loop through the referenced child entities that haven't created variations yet. This will be interesting because I've never successfully created a loop with ECA but I know it's possible. I will share my results here for the benefit of others who are trying to accomplish something similar.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Assigning issue credits.

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

Production build 0.69.0 2024