craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.21k stars 624 forks source link

[5.x]: Incorrect CP console request URLs #15374

Closed bencroker closed 1 month ago

bencroker commented 1 month ago

What happened?

The commit https://github.com/craftcms/cms/commit/8e69802d89556d4432002fed3754404a4e8e0252 addressed constructing URLs for console requests if the @web alias wasn’t explicitly defined. Should a similar change not also be applied to CP console requests to ensure that CP URLs are output as absolute URLs?

Steps to reproduce

  1. In a custom module, create a console command that outputs an entry’s CP edit URL.
    die(\craft\helpers\UrlHelper::cpUrl());

Expected behavior

The output should be https://projectpath.ddev.site/admin.

Actual behavior

The output is /admin.

Tested in Craft 5 but this likely affects Craft 4 as well.

Craft CMS version

5.2.7

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

brandonkelly commented 1 month ago

We’ll discuss!

brandonkelly commented 1 month ago

Decided to make this change for 4.11 and 5.3 (#15403). It’s not as urgently needed as the actionUrl() change was, thanks to the baseCpUrl config setting.

bencroker commented 1 month ago

Lovely, thanks!

white-lukas commented 1 month ago

@brandonkelly we are now getting a typeError on the fallbackBaseUrl()

craft\helpers\UrlHelper::fallbackBaseUrl(): Argument #1 ($request) must be of type ?craft\web\Request, craft\console\Request given, 
called in /var/www/html/vendor/craftcms/cms/src/helpers/UrlHelper.php on line 646
brandonkelly commented 1 month ago

@white-lukas Thanks for letting me know. Fixed via a94c6cd2e39f88e62b8e60b80ea0a846f181b533.

sajjanstha commented 4 weeks ago

@brandonkelly Did you push the fix for above typeError on the fallbackBaseUrl() for craft 4? I am still facing the below error when I upgraded my craft cms to 4.11.0.2. Exception 'TypeError' with message 'craft\helpers\UrlHelper::fallbackBaseUrl(): Argument #1 ($request) must be of type ?craft\web\Request, craft\console\Request given, called in /var/www/html/app/vendor/craftcms/cms/src/helpers/UrlHelper.php on line 655'

brandonkelly commented 4 weeks ago

@sajjanstha Doh, forgot to apply the fix to Craft 4. Just tagged 4.11.1 with the same fix.