Closed arifje closed 10 months ago
Also seeing this with Embedded Assets 3.1.6
and Craft 4.5.3
. Clients are unable to update content as a result.
The error originates from the following line:
It doesn’t look like sourcePath
is present on the asset select input.
Could be just that we need the extra check or optional chain as referencing properties of a non-object will throw.
Here’s a possible drop-in replacement for the getActionTarget
method.
const getActionTarget: () => Object = () => {
if (Array.isArray(this.sourcePath)) {
// Craft 4.4 subfolder compatibility
const currentFolder = this.sourcePath[this.sourcePath.length - 1]
if (currentFolder?.folderId) {
return {
targetType: 'folder',
targetId: currentFolder.folderId
}
}
}
const [targetType, targetUid] = this.sourceKey.split(':')
if (targetType && targetUid) {
return { targetType, targetUid }
}
return {}
}
I’ve also stripped the typeof
checks in favour of clearer and type-checked conditions. It’s absolutely a personal preference, but I think the conditions and destructuring assignment syntax make it a bit more readable.
All of this is assuming that currentFolder
should ever be nullish.
This is working as expected for me, e.g. the following screenshot shows me logging the sourcePath
property:
Not really willing to make changes without being able to reproduce the error, since I don't want to make a change that breaks something else, and sourcePath
is actually a Craft.AssetIndex
property and I'm unsure what case causes it to be empty. Any extra information that could help identify the cause (e.g. a specific field configuration if this only happens when editing entries) is appreciated.
Thanks, @ttempleton. Where are you seeing that array you’re referencing?
Our field config;
Thanks both - I can reproduce the error and it is related to the use of variables when restricting assets to a single location.
Just want to confirm that this has only started happening when upgrading to Craft 4.5? This is just for the purpose of updating the changelog.
Thanks, @ttempleton. Glad we were able to help diagnose this.
I was seeing this with earlier versions (e.g. Craft 4.4.17
).
Thanks - just released 3.1.7 with the fix.
Amazing! Thanks, @ttempleton. Can confirm this is up and running again for us. 🙏🏻
Bug Description
Since our update to Craft 4.5.1 and Embedded Assets 3.1.6, we can't save the embeds anymore.
Steps to reproduce
Expected behaviour
No response
Embedded Assets version
3.1.6
Craft CMS version
4.5.1