diff --git a/CHANGELOG.md b/CHANGELOG.md index 50e2158623a..be86ecbdac1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft CMS 4 +## Unreleased + +- Fixed a JavaScript error that could occur when renaming assets without URLs. ([#13223](https://github.com/craftcms/cms/pull/13223)) + ## 4.4.13 - 2023-05-24 - Fixed a bug where asset sources weren‘t immediately showing a source path on a clear `localStorage` cache. diff --git a/src/elements/Asset.php b/src/elements/Asset.php index 70b9f52529b..d7363bebd19 100644 --- a/src/elements/Asset.php +++ b/src/elements/Asset.php @@ -2950,6 +2950,7 @@ protected function htmlAttributes(string $context): array 'data' => [ 'kind' => $this->kind, 'alt' => $this->alt, + 'filename' => $this->filename, ], ]; diff --git a/src/elements/actions/RenameFile.php b/src/elements/actions/RenameFile.php index dd99064781d..8483862a13e 100644 --- a/src/elements/actions/RenameFile.php +++ b/src/elements/actions/RenameFile.php @@ -41,11 +41,7 @@ public function getTriggerHtml(): ?string activate: \$selectedItems => { const \$element = \$selectedItems.find('.element') const assetId = \$element.data('id'); - let oldName = \$element.data('url').split('/').pop(); - - if (oldName.indexOf('?') !== -1) { - oldName = oldName.split('?').shift(); - } + let oldName = \$element.data('filename'); const newName = prompt($prompt, oldName);