Hello!

Nowadays to choose entity in some language, we have to switch user interface to that particular language. For example, we can't make reference to English node from ru/node/add/article, we should switch to en/node/add/article first - i.e. from Russian to English. Doesn't matter, what widget do we use: Autocomplete, Autocomplete (Tags style), Select list or Check boxes - they all are affected. Earlier you could choose entity in any language, and current interface's language wasn't took into account, but later this behaviour was changed. Would be great to return it to previous state. It will make user experience more consistent, because core Taxonomy field gives us a possibility to reference to term in language other than current language.

It would be even better, though, to add possibility to search desirable entity, taking into account it's translations. Obviously, it'll require to take into account title_field values - if there are such a field, it is provided by the Title module. If not, entity title can be used, as usual. Of course, Title and Entity Translation are de-jure contrib modules, but de-facto they are among cornerstones for D8MI, so looks like today's efforts in that direction will simplify creation Entity Reference version for D8. If there are plans for such a version, of course.

CommentFileSizeAuthor
#4 Screen Shot 2012-08-21 at 11.58.36 AM.png28.08 KBgreenc

Comments

damien tournoud’s picture

Title: Internationalization-friendly entity selection » Add support for the Title module

Nowadays to choose entity in some language, we have to switch user interface to that particular language. For example, we can't make reference to English node from ru/node/add/article, we should switch to en/node/add/article first - i.e. from Russian to English.

This is probably because the i18n module uses access control to filter out nodes per languages. Entity Reference now fully comply with access control (as it should), so there is absolutely nothing I can do here.

It would be even better, though, to add possibility to search desirable entity, taking into account it's translations. [...]

There is actually one good point buried in there: we should add support for the title module. The problem is, the entity label doesn't properly support translations in Drupal 7, so we are going to need to hardcode it as a one-off thing.

pieterdc’s picture

Status: Active » Needs work

A little howto:

If you don't want i18n to filter the results; then change a setting at admin/config/regional/i18n/select
Either uncheck 'Select nodes by language' and/or 'Select taxonomy terms by language'.
Or add 'entityreference' to the list of tags to skip.

I choose the latter.

To clarify which node's language version I'll be referencing to, from an entityreference autocomplete form field, I modified getLabel() in base.inc.
Replace return entity_label($this->field['settings']['target_type'], $entity);
with return $entity->{language} .' - '. entity_label($this->field['settings']['target_type'], $entity);
This puts the languagecode in front of each suggested result at the autocomplete field.

renat’s picture

@PieterDC, thank you for this tip!
So we only have to add ability to enter translated Title field value (now you have to enter original title, though Autocomplete widget will translate it's hints) to gain perfect Title module support.

greenc’s picture

Category: feature » bug
StatusFileSize
new28.08 KB

I was wondering if you were still planning to add support for the Title module? We're looking at using both for a site and it works well in that the translation shows up as it should (this doesn't work at all using the References module), however the sorting ignores the translated title and sorts according to the source title.

I've attached a screenshot to illustrate the issue (in case there were any doubts based on the description above)... you'll notice États-Unis and Royaume-Uni aren't where they should be when viewing as example.com/fr/node/123/edit for an, in this case, English language default installation.

I marked this as a bug since it looks a bit buggy, though it could well be a feature request.

Many thanks

dave reid’s picture

Status: Needs work » Closed (duplicate)
renat’s picture

Confirm, with the patch applied all works fine. Of course you have to set Entity Reference field Entity Selection property to "Views: Filter by an entity reference view", and create an Entity Reference view with appropriate Node: Title field. Simple entity selection mode is not suitable for that task.