fix ajax entity loading cache langauges context

This commit is contained in:
2018-05-02 14:13:42 +02:00
parent 7f6eda4d14
commit 861dfb4176
@@ -19,7 +19,17 @@ use Drupal\core\render\RenderContext;
class EdlpAjaxController extends ControllerBase {
private function query() {
$this->entity = entity_load($this->entity_type, $this->id);
$this->langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
$entity = entity_load($this->entity_type, $this->id);
if ($entity->hasTranslation($this->langcode)){
$this->entity = $entity->getTranslation($this->langcode);
}else{
$this->entity = $entity;
}
if($this->entity){
switch($this->entity_type){
@@ -174,6 +184,7 @@ class EdlpAjaxController extends ControllerBase {
'bundle' => $this->bundle,
'entity_type' => $this->entity_type,
'rendered'=> $rendered,
'language' => $this->langcode
];
// if content type page (productions) :
@@ -227,6 +238,9 @@ class EdlpAjaxController extends ControllerBase {
'tags' => [
'edlp-ajax-cache',
// $this->entity_type.':'.$this->id // not necessary as we add $renderable as CacheableMetadata to the response
],
'contexts' => [
'languages:language_content'
]
];