Browse Source

getpathtranslation invalid path temporary workarround

bach 3 years ago
parent
commit
7e460b9764

+ 8 - 0
web/modules/custom/materio_decoupled/src/Controller/MaterioDecoupledLanguageLinks.php

@@ -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 it is too large
+ 0 - 26
web/themes/custom/materiotheme/assets/dist/main.js


+ 11 - 7
web/themes/custom/materiotheme/assets/scripts/main.js

@@ -184,13 +184,17 @@ import { MA } from 'vuejs/api/ma-axios'
       MA.post(`materio_decoupled/path_translation_links?`, params)
         .then(({ data }) => {
           console.log('Path translations links', data)
-          links.forEach((link, i) => {
-            console.log("language link",path , link)
-            let hreflang = link.getAttribute('hreflang')
-
-            link.setAttribute('href', data.links[hreflang].url)
-            link.innerHTML = data.links[hreflang].title
-          });
+          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')
+
+              link.setAttribute('href', data.links[hreflang].url)
+              link.innerHTML = data.links[hreflang].title
+            });
+          }
         })
         .catch(error => {
           console.warn('Path translations links', error)

Some files were not shown because too many files changed in this diff