Skip to content

Commit

Permalink
Merge pull request #16220 from craftcms/bugfix/16214-duplicating-elem…
Browse files Browse the repository at this point in the history
…ents-with-dynamic-asset-subpath

when duplicating find dynamic folder by duplicateOf element
  • Loading branch information
brandonkelly authored Nov 27, 2024
2 parents 2ccb651 + f7b62f4 commit 2ad3709
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Craft CMS 4

## Unreleased

- Fixed an error that could occur when duplicating an element with an Assets field that had a dynamic subpath. ([#16214](https://github.com/craftcms/cms/issues/16214))

## 4.13.3 - 2024-11-22

- Element indexes now sort by ID by default, for sources that don’t define a default sort option.
Expand Down
3 changes: 3 additions & 0 deletions src/fields/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,9 @@ private function _findFolder(string $sourceKey, ?string $subpath, ?ElementInterf
if ($isDynamic) {
// Prepare the path by parsing tokens and normalizing slashes.
try {
if ($element?->duplicateOf) {
$element = $element->duplicateOf;
}
$renderedSubpath = Craft::$app->getView()->renderObjectTemplate($subpath, $element);
} catch (InvalidConfigException|RuntimeError $e) {
throw new InvalidSubpathException($subpath, null, 0, $e);
Expand Down

0 comments on commit 2ad3709

Please sign in to comment.