Commit f52a377e authored by Patrick Kannekens's avatar Patrick Kannekens
Browse files

Issue #3110159 by kalvis: Chart config options are shown in the original...

Issue #3110159 by kalvis: Chart config options are shown in the original language when embedding chart's translation
parent 59858634
Loading
Loading
Loading
Loading
+7 −6
Changes for src/Plugin/entity_embed/EntityEmbedDisplay/Easychart.php: 7 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\easychart\Plugin\entity_embed\EntityEmbedDisplay;

use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\easychart\EasychartHelper;
use Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayBase;
@@ -41,14 +42,18 @@ class Easychart extends EntityEmbedDisplayBase {
    $route_match = \Drupal::routeMatch();

    $entity = $this->getEntityFromContext();
    $values = $entity->get('easychart')->getValue();

    if ($entity instanceof ContentEntityBase) {
      $translation = $entity->getTranslation($this->getLangcode());
      $values = $translation->get('easychart')->getValue();
    }

    // We are in preview.
    if ($route_match->getRouteName() == 'embed.preview') {
      $show_placeholder = TRUE;

      // Try to render preview in the editor.
      if (!is_null($entity)) {
        $values = $entity->get('easychart')->getValue();
      if (!empty($values[0]['config'])) {
        $http_client = \Drupal::httpClient();
        $options = [];
@@ -67,7 +72,6 @@ class Easychart extends EntityEmbedDisplayBase {
          }
        }
      }
      }

      // Show placeholder.
      if ($show_placeholder) {
@@ -78,10 +82,8 @@ class Easychart extends EntityEmbedDisplayBase {
    }
    // Otherwise, render the chart.
    else {
      if (!is_null($entity)) {
      $delta = 0;
      $entity_id = $entity->id();
        $values = $entity->get('easychart')->getValue();
      $output = EasychartHelper::easychartPrintChart($values[0], $entity_id, $delta);
      if (!empty($output)) {
        $element[$delta] = ['#markup' => $output['markup']];
@@ -90,7 +92,6 @@ class Easychart extends EntityEmbedDisplayBase {
          'csv' => $output['csv'],
        ];
      }
      }

      if (!empty($element)) {
        EasychartHelper::addRenderLibraries($element);