From 4e47c6022bbf4b5eab36052a70c4dbec5e62d008 Mon Sep 17 00:00:00 2001 From: Harald Atteneder Date: Thu, 8 Jul 2021 13:22:10 +0200 Subject: [PATCH] Add skipFieldHandles config setting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add `skipFieldHandles` to opt-out of populating certain fields. Useful if you want to avoid getting your matrix field deleted on every import… --- src/services/Process.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/services/Process.php b/src/services/Process.php index 38f7bc85..eb26f3ef 100644 --- a/src/services/Process.php +++ b/src/services/Process.php @@ -369,6 +369,19 @@ public function processFeed($step, $feed, &$processedElementIds) // Set the attributes for the element $element->setAttributes($attributeData, false); + // We can opt-out of populating certain fields + $skipFieldHandles = Plugin::$plugin->service->getConfig('skipFieldHandles', $feed['id']); + + if ($skipFieldHandles) { + $feed['fieldMapping'] = array_filter($feed['fieldMapping'], function ($fieldInfo, $fieldHandle) use ($skipFieldHandles) { + $skip = in_array($fieldHandle, $skipFieldHandles); + if ($skip) { + Plugin::info('Skipped `{field}` due to config setting.', ['field' => $fieldHandle]); + } + return !$skip; + }, ARRAY_FILTER_USE_BOTH); + } + // Then, do the same for custom fields. Again, this should be done after populating the element attributes foreach ($feed['fieldMapping'] as $fieldHandle => $fieldInfo) { if (Hash::get($fieldInfo, 'field')) {