- Issue created by @coaston
- πΊπΈUnited States apmsooner
When feeds imports field data, it is always going to write to the complete field table which in this case contains all 10 columns. Whatever column data your source doesn't provide to the feed is indeed going to result in a null value. I don't know any way around that other than to perhaps export your existing data for that field and merge the other csv data into it so everything is there. You may be able to do some trickery with an event subscriber or something but I'm honestly not sure. Maybe you could ask suggestions as well in the #feeds slack channel?
- πΈπ°Slovakia coaston
What a pity.
For a select list with a several options is good workaround to use eca β module using Views as follow:
1.Create a standard boolean field called "feedsimport" to content type
2.Use feeds module and update to value 1 all content types which needs to be updated.
3.Create view and use filter to boolean 1 so only nodes which need to be updated are selected.
4.Create eca model > Use Loop of view with "Views: Execute query" task and "Set: Field value" of your custom field(subfield) likecustom_field:status
with your prefered value like "Open" or "Closed"This works fine for simple select list, but in my case like Location ,or city which is always different ECA won't help I guess :(
- πΊπΈUnited States apmsooner
Hmm, I'm not sure I understand what you are trying to accomplish there with ECA or really how feeds fits into that. I do think in a custom module you can use an EventSubscriber that could manipulate the values on presave which means I suppose just preserving whatever values already exist.
Here's an example of something i did in my own custom module that perhaps you could find useful to adapt. I don't know if this would help or not and maybe Feeds just isn't the right solution for you. I just don't really understand the use case your describing.
<?php namespace Drupal\nutrition\EventSubscriber; use Drupal\feeds\Event\EntityEvent; use Drupal\feeds\Event\FeedsEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Subscribe to events from the `feeds` module. */ class FeedsEventSubscriber implements EventSubscriberInterface { /** * {@inheritDoc} */ public static function getSubscribedEvents(): array { $events = []; $events[FeedsEvents::PROCESS_ENTITY_PRESAVE][] = 'presave'; return $events; } /** * Acts on presaving an entity. * * @param \Drupal\feeds\Event\EntityEvent $event * The feed event. */ public function presave(EntityEvent $event) { $json = $event->getItem()->get('portions_json'); $values = json_decode($json, TRUE); $event->getEntity()->get('field_weights')->setValue($values); } }
- πΊπΈUnited States apmsooner
BTW, you tagged this to version 3.0.3 and there is no further development that is gonna go towards that branch. I'm only keeping it around for people that havn't upgraded. I'd highly recommend upgrading to the 3.1.x version as theres substantial new features and bugfixes.
- πΈπ°Slovakia coaston
Thank you.
Well, i currently cannot update php (8.1.26) to later version due to stakeholders so I was afraid to update to 3.1 if there is not any 8.2+ php requirement. But if not i will because some modules need higher version of php already.
But back to topic - i just wanted to provide workaround for others with the same problem that ECA can update custom_field and its subdields without loosing data.
You can create one standard field and use it for feeds cvs import and then with eca connect it with custom_field and replace values so in this case data wont be lost.
Example:
I do have csv with 2 columns and 1000 rows: first column : node_id
Second column : cityCity is our custom_field:city but i cannot update it using feeds because the rest 10 subdields will be replacet with value null.
So i can create a standard field called "feedimport" and it can be a string one for example. In feeds maper i will use first column node_id and the second city as source but feedimport as my field.
Will import 1000 cities to my feedimport field
Now will create views and get all nodes which dont have feedsimport field blank so i will get exactly 1000nodes i need.
Now using eca i can loop the view and replace the value from its feedsimport field to custom_field:city and right after clear feedsimport field to null so it is blank and will be ready for next use.This looks a bit complex, but it is no coding solution and one time configuration only because that feedsimport field you can reuse for any content type just update eca with the exact custom_field:subfield next time is needed.
So i can repeat the process for my other subfields if needed. But yeah if more then 2 fields need to be updated this is time consuming.
But i will give a try and try to update your code to see if it helps for my purpose.