1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

EntityQuery not returning content based on language

Discussion in 'Programming/Internet' started by SuperTony, Oct 8, 2018.

  1. SuperTony

    SuperTony Guest

    I'm trying to get a list of all of a specific content type, but my entityQuery is only returning the original language of the site (English). Here's my code:

    public function fetchDocumentReferenceOptions() {
    $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
    $query = \Drupal::entityQuery('node')
    ->condition('status', 1)
    ->condition('type', 'document')
    ->condition('langcode', $language)
    ->sort('title', 'ASC');

    $nids = $query->execute();

    $nodes = node_load_multiple($nids);

    $options = [];

    foreach($nodes as $node)
    // check if the document (content type) has an uploaded file
    if ($node->field_document->entity) {
    $options[$node->id()] = $node->getTitle();

    return $options;


    This is how I call the function:

    '#options' => $DocumentReferenceCore->fetchDocumentReferenceOptions(),

    What I am expecting, based on condition for langcode would be that, if, for example, I am editing a Chinese language node (translated from the original English node), I should see Chinese nodes, and the content being returned, but instead I am still seeing the original English content.

    What am I doing wrong here?

    Login To add answer/comment

Share This Page