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
@@ -6,6 +6,8 @@ use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormBuilder;
use Drupal\search_api\Entity\Index;
use Drupal\Core\Url;
use Drupal\Core\Language\LanguageInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -72,14 +74,29 @@ class EdlpSearchController extends ControllerBase {
$this->buildRenderable();
$rendered = render($this->renderable);
$data = [
'rendered' => $rendered
];
// translations links
$route_name = 'edlp_search.edlp_search_controller_searchForm';
$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;
}
// TODO: make respponse cachable
$response = new JsonResponse();
$response->setData([
'rendered'=> $rendered,
]);
$response->setData($data);
return $response;
}
public function autocomplete(Request $request){