getpathtranslation invalid path temporary workarround

This commit is contained in:
Bachir Soussi Chiadmi 2021-03-08 14:41:22 +01:00
parent 30b2c9267b
commit 7e460b9764
3 changed files with 19 additions and 63 deletions

View File

@ -51,6 +51,14 @@ class MaterioDecoupledLanguageLinks extends ControllerBase {
// build the links
$url_object = \Drupal::service('path.validator')->getUrlIfValid($path);
// Call to a member function getRouteName() on bool in Drupal\materio_decoupled\Controller\MaterioDecoupledLanguageLinks->getPathTranslationLinks()
if (!$url_object) {
// if path does not exists rtuen an error
return new JsonResponse(array(
"links" = [],
"error" = "path {$path} is not valid"
));
}
$route_name = $url_object->getRouteName();
$route_parameters = $url_object->getrouteParameters();
$languages = $this->languageManager->getNativeLanguages();

File diff suppressed because one or more lines are too long

View File

@ -184,6 +184,9 @@ import { MA } from 'vuejs/api/ma-axios'
MA.post(`materio_decoupled/path_translation_links?`, params)
.then(({ data }) => {
console.log('Path translations links', data)
if (data.error) {
console.warn("error get translation paths", data.error);
} else {
links.forEach((link, i) => {
console.log("language link",path , link)
let hreflang = link.getAttribute('hreflang')
@ -191,6 +194,7 @@ import { MA } from 'vuejs/api/ma-axios'
link.setAttribute('href', data.links[hreflang].url)
link.innerHTML = data.links[hreflang].title
});
}
})
.catch(error => {
console.warn('Path translations links', error)