I know I can simply add language to displayed title of a node in Entity Reference field based on views. What I failed to discover is how to limit possible values to only show and allow matching ones.

  • When current node is language independent, all nodes should be listed as possible in reference field.

  • When node has language defined, only nodes of the same language, or undefined language, should be available.

I don't really mind wrong selection to be saved in database if language of node will be changed, as it shouldn't happen often enough to be a problem. I simply don't want "wrong" nodes on the list of available reference choices. On-save validation would be nice, but isn't a must-have.

I tried to use view to populate entityreference field's dropdown on node edit form:

Screenshot of field settings

My big block is how to access a language of a current node in view that provides list of available entities. I can't find a way other than to guess using current UI language, but that may be wrong for edits and usually is wrong on new node creation. Ideally, the entity reference field should repopulate via AJAX according to the language selected in the node edit from.

For the sake of future visitors I would appreciate complete answer. Of course answer not based on views will be appreciated, too.

  • Since I have few knowledge on Entity Ref, It is difficult to understand the question, So are you looking something similar to this module drupal.org/project/cer
    – Bala
    Sep 4, 2013 at 11:25
  • I don't know may be this could be the answer drupal.org/project/reference_option_limit . You can also integrate with the entity reference fields
    – Bala
    Sep 4, 2013 at 11:29
  • @Bala Reference field option limit might be an answer. Certainly what it claims to do would be enough. If you can check if it and post as an answer, would be nice. I'll test it when I'll find a bit of time, of course, but I cannot reward bounty on comments :P
    – Mołot
    Sep 5, 2013 at 6:36
  • Still searching for you have look drupal.org/project/entityreference_dynamicselect_widget
    – Bala
    Sep 5, 2013 at 13:20
  • @Bala - no use unless I want to repeat language next to reference dropdown. Maybe could be used as a codebase for custom solution, but that's all. Now experimenting with computed fields (@language) and reference option limit, but field can be computed on read and on save it seems... not live on edit form.
    – Mołot
    Sep 5, 2013 at 13:27

5 Answers 5


Reference field option limit module allows reference fields of several types to have their widgets' available options limited by the values of other fields in the current entity.

It currently supports taxonomy term and entity reference fields.

  • Docs looks good. To bad I cannot make it work. Issue 2082217 might or might not be the reason. We'll see. Will test more. Anyway, it seems to be a nice code to start with.
    – Mołot
    Sep 5, 2013 at 7:19
  • Sadly, language is not exposed as a field... Testing continues ;)
    – Mołot
    Sep 5, 2013 at 9:10

I can suggest some "concepts" of solution with Views.

I didn't understood if you succeed to define target node language. (if no, write a comment, I'll update the answer).

Step1. You are able to pass arguments to the view that filters entityreference field. Then it's possible to add your language to the field views args programmatically in $field['settings']['handler_settings']['view']['args'];.

Step2. You can create custom contextual filter programmatically. Filter will pass the language id. This contextual will change View language using agrument value. you can change language in query alter - query() method of your child class of views_handler_argument.

Then just dpm($this) in the query() method and change language value to your argument.

  • Not bad concepts, but it seems basically you are telling me to rebuild Reference field option limit Bala suggested, only with language instead of fields :)
    – Mołot
    Sep 9, 2013 at 7:55
  • Yes, you have now solution for both fields and language :) Unfortunately I'm not common with "Reference field option limit". I suggested custom coding
    – milkovsky
    Sep 9, 2013 at 10:24

Check out Translated Entity Reference module.

Another option is to create your custom view to render your Entity Reference field selectable options. Just:

  1. Create a new view
  2. Add a new Entity Reference View Widget
  3. Add a filter for your content type
  4. Add a new contextual filter for field "Language"
  5. Select "Provide default value" + "PHP code" (maybe you will need "Views PHP" module for this)
  6. Enter this code on "PHP contextual filter code" textarea:

    global $language; $lang = $language->language;

    $node = menu_get_object(); if (!empty($node)) { $lang = $node->language; } return $lang;

  7. Edit your Entity Reference field and select your new custom view as entity selection mode


I'm looking for the same thing.

The closest I got was by using the current user's language. The current user's language will be determined by what you select in /admin/config/regional/language/configure.

  • add relationship "Entity translation: translations"
  • add filter "Entity translation: Language (=Current user's language)"

Also, this link cleared the field_title issue for me: https://drupal.org/node/1327012.

So, for example, going to /en/node/add will populate the entity view with the referenced entities in English. But, if the user changes the language on the edit form the view will remain the same.

This solution would suffice if the referenced entities were the same in all languages and simply translated (like the "localize terms" functionality that that core taxonomy translation provides).

The only other 'quick and dirty' way I can think of is editing the output of the title field in views and adding a css class according to the language. Then writing some jquery that shows/hides the entities by mapping the class of the entity in the view to the language selection field.

*Ideally, the entity view should repopulate via ajax according to the language selected in the node edit from.*

If anybody has any ideas please let us know.


  • It does not actually provide an answer, only something colse + comments. If you don't mind maybe we should integrate these comments into my question? On the other hand, you would not get reputation from that question... I will not flag it or anything
    – Mołot
    Sep 4, 2013 at 6:10
  • That's why I said that "I'm looking for the same thing". I just thought that my comments might be helpful to you and others who might try to answer. Feel free to integrate my comments into your question. I'm not expecting any points or anything.
    – gkom
    Sep 28, 2013 at 15:05

Field reference

Depending on configuration, authors can pick fields from the same node/entity, from other nodes/entities, from specific revisions, from specific languages, or even a specific delta value within the field. Fields can be displayed using either the 'full' or 'teaser' mode from their original node/entity.

  • Quick test seems to indicate that you need to hard-configure language and it will not change live. I'll be glad if you can prove me wrong. Last but not least, I need to reference entities, not their fields. But that's a minor problem I guess.
    – Mołot
    Sep 5, 2013 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.