You are here

function ParagraphsFrontendUIController::forceValueLanguage in Paragraphs frontend ui 8

Same name and namespace in other branches
  1. 8.2 src/Controller/ParagraphsFrontendUIController.php \Drupal\paragraphs_frontend_ui\Controller\ParagraphsFrontendUIController::forceValueLanguage()

After reloading a translated paragraph field with ajax, the original language is shown instead of the translation I am using the workaround provided in https://www.drupal.org/project/paragraphs/issues/2753201#comment-11834096 to force the language

Parameters

\Drupal\Core\TypedData\TypedData $value:

$language:

1 call to ParagraphsFrontendUIController::forceValueLanguage()
ParagraphsFrontendUIController::refreshWithAJaxResponse in src/Controller/ParagraphsFrontendUIController.php
Helper function to refresh the field with ajax.

File

src/Controller/ParagraphsFrontendUIController.php, line 187

Class

ParagraphsFrontendUIController
Controller for up and down actions.

Namespace

Drupal\paragraphs_frontend_ui\Controller

Code

function forceValueLanguage(TypedData &$value, $language) {
  $parent = $value
    ->getParent()
    ->getValue();
  if (!$parent
    ->hasTranslation($language)) {
    return;
  }
  $parent_translated = $parent
    ->getTranslation($language);
  $name = $value
    ->getName();
  $adapter = EntityAdapter::createFromEntity($parent_translated);
  $value
    ->setContext($name, $adapter);
}