diff --git a/CHANGELOG.md b/CHANGELOG.md index b818ece2..1670693b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Feed Me +## Unreleased + +- Fixed a PHP error that could occur when importing Assets that had a missing filename. ([#1481](https://github.com/craftcms/feed-me/pull/1481)) + ## 6.2.0 - 2024-07-09 > **Warning** diff --git a/src/fields/Assets.php b/src/fields/Assets.php index a1bdd27f..09978fed 100644 --- a/src/fields/Assets.php +++ b/src/fields/Assets.php @@ -118,8 +118,10 @@ public function parseField(): mixed $base64ToUpload = []; $filenamesFromFeed = $upload ? DataHelper::fetchArrayValue($this->feedData, $this->fieldInfo, 'options.filenameNode') : null; - // see https://github.com/craftcms/feed-me/issues/1471 - $filenamesFromFeed = array_splice($filenamesFromFeed, $nodeKey, count($value)); + if ($filenamesFromFeed) { + // see https://github.com/craftcms/feed-me/issues/1471 + $filenamesFromFeed = array_splice($filenamesFromFeed, $nodeKey, count($value)); + } // Fire an 'onAssetFilename' event $event = new AssetFilenameEvent([ diff --git a/src/templates/_includes/fields/assets.html b/src/templates/_includes/fields/assets.html index 1e49b21b..eb94839f 100644 --- a/src/templates/_includes/fields/assets.html +++ b/src/templates/_includes/fields/assets.html @@ -75,7 +75,7 @@ label: 'Use this filename for assets created from URL:'|t('feed-me'), name: 'options[filenameNode]', value: hash_get(feed.fieldMapping, optionsPath ~ '.filenameNode') ?: '', - options: feedData, + options: feedData|filter(option => option.value != 'usedefault'), class: 'selectize fullwidth', }) }}