Problem/Motivation

Both EntityReference_SelectionHandler_Translation_Generic_node and EntityReference_SelectionHandler_Translation_Generic_taxonomy_term are wrong. With it's current code they only work on Entity Reference (ER) in one case:

Node context:
ER field that points to nodes: OK
ER field that ponts to taxonomies: KO *

Taxonomy context:
ER field that points to nodes: KO
ER field that ponts to taxonomies: KO

The problem is that in EntityReference_SelectionHandler_Translation_Generic_node the function i18n_node_i18n_context_language is called to obtain the language of the node in context but the ER field could be in a taxonomy context too!

The same problem happens in EntityReference_SelectionHandler_Translation_Generic_taxonomy_term: the function i18n_taxonomy_i18n_context_language is called to obtain the language of the taxonomy in context but the ER field could be in a node context too!

* This notice shows up:

Notice: Undefined index: locale in EntityReference_SelectionHandler_Translation_Generic_taxonomy_term->entityFieldQueryAlter() (line 95 of /sites/all/modules/contrib/translated_entityreference/plugins/selection/EntityReference_SelectionHandler_Translation_Generic.class.php).

It is highly recommended to also apply patch of issue 2762971.

Proposed resolution

Call both i18n_node_i18n_context_language and i18n_taxonomy_i18n_context_language in both handlers and then use the result of two which is not empty.

Fix EntityReference_SelectionHandler_Translation_Generic_taxonomy_term (it lacks getReferencableEntities implementation).

Remaining tasks

None. Test this by editing nodes and taxonomies with ER fields.

Comments

rcodina created an issue. See original summary.

rcodina’s picture

Issue summary: View changes
rcodina’s picture

Title: Handler EntityReference_SelectionHandler_Translation_Generic_taxonomy_term doesn't get called » Module's entity handlers for Entity Reference fields that points to nodes and terms are wrong
Issue summary: View changes
rcodina’s picture

Issue summary: View changes
rcodina’s picture

Issue summary: View changes
rcodina’s picture

Priority: Normal » Critical
rcodina’s picture

StatusFileSize
new2.33 KB
rcodina’s picture

Issue summary: View changes
rcodina’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new4.18 KB
rcodina’s picture

Issue summary: View changes
rcodina’s picture

Issue summary: View changes
rcodina’s picture

Issue summary: View changes
rcodina’s picture

Issue summary: View changes
StatusFileSize
new4.38 KB
new1.04 KB

Custom implementation of getReferencableEntities didn't follow configuration of field.

rcodina’s picture

StatusFileSize
new4.41 KB
new615 bytes

Solved bug on creation.

rcodina’s picture

StatusFileSize
new6.86 KB
new3.66 KB

Optional: I improved patch on 14 so now the entity labels appear with a suffix containing its translation in website default language. The translation is added between parenthesis. This may be useful when you admin a website in languages you don't know. However, I recommend patch 15.

rcodina’s picture

AsadKamil’s picture

Hi All,
This patch 15 works fine for 7x branch. Thanks.

root@asad-Vostro-3550:/var/www/html/git/translated_entityreference# git apply -v module_s_entity-2764093-15.patch 
Checking patch plugins/selection/EntityReference_SelectionHandler_Translation_Generic.class.php...
Applied patch plugins/selection/EntityReference_SelectionHandler_Translation_Generic.class.php cleanly.
root@asad-Vostro-3550:/var/www/html/git/translated_entityreference#
rcodina’s picture

@AsadKamil Download latest dev version and use module_s_entity-2764093-15.patch, edit_when_user_changes-2762971-19.patch and module_not_working-2267853-7.patch patches. Remember to enable the submodule!