Feeds - Deselect field from mapping

Created on 10 April 2025, 15 days ago

Problem/Motivation

I do have a custom field with 10 subfields (columns). However I do have a request to update by bulk using feeds just 3 columns of 10 only, like status, address and city.

However when I map a custom field I can see there all 10 subfields which is fine. However in my CSV file I would like to have only 4 columns like id, status, address and city.

When I do import using feeds it currently overrides all the rest 6 columns with Null (blank) value so data are lost forever.

For the standard field when there is a mapped field - it just ignore it if my csv does not have such column.

Is there any way to update only required columns (subfields) and does not touch /impact the rest ?

πŸ’¬ Support request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΈπŸ‡°Slovakia coaston

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • 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) like custom_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 : city

    City 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.

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner
Production build 0.71.5 2024