There’s not really any way to know what context a request is coming from without manually adding that context e.g. via query parameters.
You can to some extent identify what context the request is going to though - so if your in-CMS request is going through a ModelAdmin
or other controller that descends from LeftAndMain
then you can check if (Controller::has_curr() && (Controller::curr() instanceof LeftAndMain))
.
You could alternatively check the request URL to see if it is in an admin-like route, which is how tractorcow/silverstripe-fluent
handles it.
If you’re trying to tell whether your record is being viewed in the CMS preview panel or not, that’s even easier - just check for $request->getVar('CMSPreview')
- if that’s truthy, then it’s in the CMS preview panel, otherwise it isn’t.
Ultimately it all depends on exactly what you mean by “if the request is being made from within the CMS” and what you’re trying to do with that information.