Check if getSetById exists when querying globals
Wrapping the $set in an if check fixed an issue querying globals that returned an error Trying to get property of non-object.
This seems like a good fix. Although, I'm not totally clear on what issue it solves?
First we get all the set ids and loop over them,
$setIds = \Craft::$app->globals->getAllSetIds();
foreach ($setIds as $id) {
Then on each set we get the details of the set,
$set = \Craft::$app->globals->getSetById($id, $siteId);
$sets[$set->handle] = $set;
Since the code from the first blog grabs all the set ids why would the code from the second block ever not return a set?
I assume I'm missing something obvious here. Sorry for being dense.
No worries. I'm not sure how to explain it as far as the code goes. I tested querying globals on a Craft install that only has one site. Things work as expected.
However, I get the error of Trying to get property of non-object when querying globals in a multi-site environment. Maybe something with the $siteId?
@markhuot this seems to fix the same issue for me. $set is null/undefined at some point.
Probably its something with the $siteId which is 'default' or 1 in my case. Unfortunately I have no time to setup a dev environment for craft and track it down myself.
Right now I am using "craftcms/cms": "3.1.14" with "markhuot/craftql": "1.3.1".
If you want to have a closer look I could provide you with my docker image + project.yaml - just let me know.
👋🏼 @markhuot I apologize for getting all of the wires crossed with this PR. Is this the correct place you were referencing here?