I created inline_entity_form support for a custom entity provided by a contributed module. In doing so I ran into a problem with the use of entity_id($entity_type, $entity) in line 1119 of inline_entity_form.module
$entity_ids[] = array($values['settings']['column'] => entity_id($entity_type, $item['entity']));
The custom entity I was adding support for provided both the "name" as well as "entity_id", and according to documentation for entity_id() here, it says that "Unlike entity_extract_ids() this function returns the name of the entity instead of the numeric id, in case the entity type has specified a name key."
The $entity_ids[] array seems to me needs to collect the "entity_id" as opposed to entity "name". The problem I was having elsewhere(sorry I don't remember where) arose because the array provided "entity_name" instead of "entity_id".
Upon looking at the documentation for entity_extract_ids() it became clear to me that if I used this function instead it will solve the problem. So I replaced the above line by following:
$entity_extracted_IDs = entity_extract_ids($entity_type, $item['entity']);
$entity_ids[] = array($values['settings']['column'] => $entity_extracted_IDs[0]);
It worked like a charm for me.
So, if somebody is adding inline_entity_form support for a custom entity and that entity provides both the "name" and "entity_id" keys, then this solution may help avoid problems.
Much Thanks to all the originators, maintainers and contributors to this module and all the other modules out there. You guys are simply priceless and awesome!
Comments
Comment #1
bojanz commentedPushed a fix.