Langcode isse when loading entity into token

Issue information

From user: jurgenhaas

Contribution record

Fork management

Problem/Motivation

When loading an entity into the token system, the modeller can now also select the language they want to load. If they select the default "Interface language", then we get the following error message:

Warning: Illegal offset type in Drupal\Core\Entity\ContentEntityBase->hasTranslation() (line 938 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

Drupal\Core\Entity\ContentEntityBase->hasTranslation(Object) (Line: 199)
Drupal\eca_content\Plugin\Action\TokenLoadEntity->loadEntity(Object) (Line: 163)
Drupal\eca_content\Plugin\Action\TokenLoadEntity->access(Object) (Line: 45)
Drupal\eca\Entity\Objects\EcaAction->execute(Object, Object, Array) (Line: 173)
Drupal\eca\Processor->executeSuccessors(Object, Object, Object, Array) (Line: 175)
Drupal\eca\Processor->executeSuccessors(Object, Object, Object, Array) (Line: 131)
Drupal\eca\Processor->execute(Object) (Line: 35)
Drupal\eca\EventSubscriber\EcaBase->onEvent(Object, 'eca.content_entity.update', Object)
call_user_func(Array, Object, 'eca.content_entity.update', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'eca.content_entity.update') (Line: 70)
Drupal\eca\Event\TriggerEvent->dispatchFromPlugin('content_entity:update', Object) (Line: 125)
Drupal\eca_content\HookHandler->update(Object) (Line: 85)
eca_content_entity_update(Object)

This is because of this code:

<?php
$langcode
= $config['langcode'] === '_interface' ? \Drupal::languageManager()->getCurrentLanguage() : $config['langcode'];
?>

The langcode will be a LanguageInterface object but needs to be a string. Adding ->getId() resolves the issue.

Edited by drupalbot
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information