entity value process plugin docs say 'langcode' is a reference, but it's treated as a value

Created on 30 November 2021, over 3 years ago
Updated 16 May 2025, about 21 hours ago

Problem/Motivation

The docs for EntityValue say:

 * For content entities, if a langcode is given, that translation is loaded.
 * The langcode is a reference so can be dynamic.
 *
 * Example:
 * @code
 * process:
 *   field_foo:
 *     plugin: entity_value
 *     source: field_noderef/0/target_id
 *     entity_type: node
 *     langcode: @_langcode
 *     field_name: field_foo
 * @endcode
 *

This makes it look like the value of the 'langcode' property is a reference to a source or destination value on the current row.

However, the code doesn't do this at all:

    $this->langCodeRef = isset($this->configuration['langcode']) ? $this->configuration['langcode'] : NULL;

This is just taking the value of the property.

The next time we see langCodeRef is here:

    $langcode = $this->langCodeRef;
    $arrays = array_map(function (EntityInterface $entity) use ($langcode) {
      if ($entity instanceof ContentEntityInterface) {
        if ($langcode) {
          $entity = $entity->getTranslation($langcode);
        }

This means that the exact value of the property is passed to getTranslation(). With the example configuration in the docs, that means a translation for the language '@_langcode' is going to be fetched. This will cause an error:

> Invalid translation language (@_langcode) specified.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

6.0

Component

Documentation

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇰Denmark ressa Copenhagen

    Thanks for updating the documentation, though I think the current example is misleading:

     * process:
     *   field_foo:
     *     plugin: entity_value
     *     source: field_noderef/0/target_id
     *     entity_type: node
     *     langcode: es

    From that example, I get the impression I can simply add a language code, like es, en or da. But then I got this error:

    [error] SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'langcode' cannot be null: UPDATE "node" SET "vid"=:db_update_placeholder_0, "type"=:db_update_placeholder_1, "uuid"=:db_update_placeholder_2, "langcode"=:db_update_placeholder_3

    I needed instead to set the hardcoded value with default_value like this:

      langcode:
        plugin: default_value
        default_value: da
    

    So I believe this assumption is wrong, since it looks to me like it needs a reference:

    I would say set it to an actual language code so it's clear.

    Should we reopen, or fix in a new issue?

Production build 0.71.5 2024