- 🇦🇺Australia marc.groth
I had a similar requirement and I implemented it by following the instructions on this page: https://www.drupal.org/docs/contributed-modules/feeds/feeds-howtos/alter... →
In particular, these were the files I added/updated:
1. EventSubscriber file
I opted for the first option of the aforementioned link. My alterItems() function looked something like this:
$link_target = $item->get('link_target'); if (!empty($link_target)) { $options = [ [ 'attributes' => [ 'target' => $link_target, ], ], ]; $item->set('link_target', $options); }
The 'options' data for the link field needs to be an associative array and in my case I only needed to update the 'target'... So I was able to create the attributes as above... But you could easily have multiple attributes in the CSV file (one per column for example) and then combine them using the above code as a guide/starting point.
2. Feed config file
In my CSV I had a column that was used for the target. I just needed to update my existing link field mapping in the config file and add the following line:
options: link_target
Where 'link_target' is the ID of the relevant 'Custom source' mapping config. So the full entry for the link field in the config file was as follows:
- target: field_link map: uri: link title: '' options: link_target settings: language: null
For some reason I had to add a 'Skip if empty' feeds tamper for the 'options' portion of the link... Otherwise I'd get PHP warnings.
After that all I had to do was import configuration, clear the cache and import the feeds items. The attributes should then be updated as expected.
Hopefully this helps anyone else who may be trying to achieve a similar thing!