language siwtchers links are working now (reloading the whole site but with the right url)

This commit is contained in:
2018-04-14 16:15:11 +02:00
parent cb2ae7ee35
commit 252149bfdc
9 changed files with 315 additions and 25 deletions
@@ -4,7 +4,9 @@ namespace Drupal\edlp_agenda\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\DrupalDateTime;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Url;
use Drupal\Core\Language\LanguageInterface;
// use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\Core\Cache\CacheableJsonResponse;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\core\render\RenderContext;
@@ -80,6 +82,23 @@ class AgendaController extends ControllerBase {
'rendered'=> $rendered
];
// translations links
// use Drupal\Core\Url;
// use Drupal\Core\Language\LanguageInterface;
$route_name = 'edlp_agenda.agenda';
$links = \Drupal::languageManager()->getLanguageSwitchLinks(LanguageInterface::TYPE_URL, Url::fromRoute($route_name));
if (isset($links->links)) {
$translations_build = [
'#theme' => 'links__language_block',
'#links' => $links->links,
'#attributes' => ['class' => ["language-switcher-{$links->method_id}",],],
'#set_active_class' => TRUE,
];
$translations_rendered = \Drupal::service('renderer')->executeInRenderContext(new RenderContext(), function () use ($translations_build) {return render($translations_build);});
$data['translations_links'] = $translations_rendered;
}
$data['#cache'] = [
'max-age' => \Drupal\Core\Cache\Cache::PERMANENT,
'tags' => ['edlp-agenda-cache']