This is a tricky one to explain so i hope i manage to get the point across…
Im using the modules plugin on a site, and the auto ID plugin. I have a module that has three buttons in it that can have urls changed via a select in the panel that has a page list in it fed from a JSON route in the config, so that you can set the button to link to any page in the site. The problem is i now need to add 4 external pages to this list. These pages are not in the site, which means they do not have an ID. Ive manually set them with a ridiculously high ID, so they can never clash with a real page. The problem is the module code filters the sites pages based on the ID, and it fails because those pages are not in the site.
How can i detect that the ID is one of those 4, for each of the three buttons and feed the correct url through?
And the important bit of the module code currently looks like this to get the ID & URL from the select (I know the URL in this is a bit ugly but its the only way i could get it to work):
// Link One
$cblocklinkurls = $module->cblocklinkurl();
$cblocklink = $site->url(). '/' .$site->index()->filterBy('autoid', '==', $cblocklinkurls);
// Link Two
$cblocklinkurlstwo = $module->cblocklinkurltwo();
$cblocklinktwo = $site->url(). '/' .$site->index()->filterBy('autoid', '==', $cblocklinkurlstwo);
// Link Three
$cblocklinkurlsthree = $module->cblocklinkurlthree();
$cblocklinkthree = $site->url(). '/' .$site->index()->filterBy('autoid', '==', $cblocklinkurlsthree);
I wish you wouldn’t use these unreadable variables…
Instead of storing those fake numbers, you might as well store the url itself as key in your JSON array. Would then also simplify the code, we wouldn’t need the array.
But i would still have to test wether it was a string or an integer though, right? If the key is a number, look it up with AutoID, else just spit out the value? So the route would look like this?..
You don’t have to check if the value is a string or a number, it is sufficient to check if it is a page or not, otherwise just print the string.
Variables: Of course, that’s up to you, but $cBlocklinkUrl is much more readable than $cblocklinkurls (which should also be singular if it is only one).
Note that I have changed your filterBy() to findBy(), because you only want to get (and you can only get) a single page, not a collection.
Nope. there is nothing anywhere that could interfere with this.
The code looks like this, ive set the route to what is in my last post about it (URL as key). The external links work fine, but picking any internal page gives me the number as the slug, not the url to the page that corresponds to that number:
No, just a blank (lang)starterkit; maybe the problem is indeed related to the modules, don’t know. But this $site->url()code just doesn’t make sense even if it delivers the correct result in your case.