Possible to eliminate warnings from cross-context link tags?

Summary

Whenever I use a link tag to create a link to a resource in another context, I get warnings in the MODX log like these:

[2023-07-21 17:13:54] (WARN @ /www/core/src/Revolution/modContext.php : 287) `87` was requested but no alias was located.
[2023-07-21 17:13:54] (INFO in MODX\Revolution\modContext::makeUrl @ resource 4) Resource with id 87 was not found in context web
[2023-07-21 17:13:54] (WARN @ /www/core/src/Revolution/modContext.php : 287) `87` was requested but no alias was located.
[2023-07-21 17:13:54] (INFO in MODX\Revolution\modContext::makeUrl @ resource 4) Resource with id 87 was not found in context web
[2023-07-21 17:13:54] (WARN @ /www/core/src/Revolution/modContext.php : 287) `87` was requested but no alias was located.
[2023-07-21 17:13:54] (INFO in MODX\Revolution\modContext::makeUrl @ resource 4) Resource with id 87 was not found in context web
[2023-07-21 17:13:54] (WARN @ /www/core/src/Revolution/modContext.php : 287) `87` was requested but no alias was located.
[2023-07-21 17:13:54] (INFO in MODX\Revolution\modContext::makeUrl @ resource 4) Resource with id 87 was not found in context web
[2023-07-21 17:13:54] (WARN @ /www/core/src/Revolution/modContext.php : 287) `87` was requested but no alias was located.
[2023-07-21 17:13:54] (INFO in MODX\Revolution\modContext::makeUrl @ resource 4) Resource with id 87 was not found in context web
[2023-07-21 17:13:54] (WARN @ /www/core/src/Revolution/modContext.php : 287) `87` was requested but no alias was located.
[2023-07-21 17:13:54] (INFO in MODX\Revolution\modContext::makeUrl @ resource 4) Resource with id 87 was not found in context web
[2023-07-21 17:13:54] (WARN @ /www/core/src/Revolution/modContext.php : 287) `87` was requested but no alias was located.
[2023-07-21 17:13:54] (INFO in MODX\Revolution\modContext::makeUrl @ resource 4) Resource with id 87 was not found in context web

There’s only one link tag in use per resource so I’m not sure why seven sets of messages are produced for each one. The resources do exist, are published, and have aliases. They are not in the web context though. I tried specifying the context like [[~[[+id]]? &context=`context_key`]] but it didn’t make a difference. I also tried deleting everything in the core/cache directory as well as saving the resources again but still no change. This isn’t causing any kind of problem, afaik; the links are being created correctly. I just like to keep things clean. I realize I could adjust the log_level setting to avoid having these messages logged, but I’d prefer to take care of the actual problem, if possible.

Environment

MODX 3.0.3, MODX Cloud, PHP 8.1

This syntax should theoretically work. (At least it did when I tested it.)

If there is no context specified, then the $modx->makeUrl() function tries to generate the URL in the current context. If that doesn’t work, a warning is logged and the code queries the correct context to use from the database.


I have no idea why you get the same output seven times though.
Where exactly do you use the link tag? Directly in the resource content or maybe in pdoResources chunk?

Also, do you use pdoTools? This extra replaces the default MODX parser, which may also affect how the tag gets parsed.

It’s a warning there to inform. There is no actual “problem” per se, but you can avoid it by specifying the context in the link tag. Otherwise, the best approach is to adjust the log_level to LOG_LEVEL_ERROR.

I am using pdoTools and, indeed, the link tag in question is in a template chunk used by pdoResources.

It seems that the number of times it prints that messages varies. I can keep refreshing the page and it’ll print it anywhere from 5 to 7 times per refresh.

I did a test with pdoResources

<!-- The resources with ID=6 is in a different context -->
[[!pdoResources?
    &parents=`0`
    &resources=`6`
    &tpl=`tplLink`
]]

Using this chunk (tplLink), I get no warnings in the error log.

[[~[[+id]]? &context=`[[+context_key]]`]]

Using the following chunk, I get the warning once (as expected).

[[~[[+id]]]]

The fact that adding the &context parameter to it didn’t change anything makes me think there must be something more to what’s going on here. I’ll have to dig some more. Thanks!