Required for alpha release

#2937717: Add support for manipulating a complete 'feeds item'/'row'.
#2937719: Multiple value handling
#2937721: Create 'SkipException' classes.

Required for full release

#2958013: [META] port remaining feeds tamper plugins

Original report by thomasmurphy

Are there plans to port tamper to Drupal 8? It has been listed as a dependency of a feeds alpha 1 release here
https://www.drupal.org/node/2917928

If you don't have the time to do this, would you be interested in taking on a co-maintainer?

Comments

thomasmurphy created an issue. See original summary.

thomasmurphy’s picture

Title: Plan to port to Drupal 8? » Plans to port to Drupal 8?
larowlan’s picture

So the plan here would be to create a new plugin manager for a plugin type of e.g. Tamperer

The interface would look something like

interface TampererInterface {
  public function tamper($originalValue);
  public function settingsForm(array $form, FormStateInterface $form_state);
  // Might not even need this.
  public function submitSettingsForm(array $form, FormStateInterface $form_state);
}

You should be able to scaffold most of that with Drupal console.

Then you'd need a couple of sample plugins.

e.g. explode would be a good starting point

ericgsmith’s picture

I've started an initial playground here: https://github.com/ericgsmith/tamper

I'm probably not going to contribute a huge amount of time but was just a bit of a play around while I've been bed ridden with post DrupalSouth flu.

It's basically just the plugin type and interface mentioned above, with a possible suggestion to get the plugin to explicitly handle single vs multiple values itself https://github.com/ericgsmith/tamper/pull/1/files

MegaChriz’s picture

twistor has given me maintainer privileges for this project! This means that we could actively use this project for developing the Tamper module now.

Note that there's an interesting discussion about whether or not develop a Tamper module: #2917928-4: Plan for 8.x-3.0-alpha1 release. (I do think that discussion should be continued in #2917926: Port Feeds Tamper to D8).

MegaChriz’s picture

Title: Plans to port to Drupal 8? » Tamper for D8
Version: 7.x-1.x-dev » 8.x-1.x-dev
Category: Feature request » Plan
Issue summary: View changes

I've added a D8 release for Tamper on this project so we can track 8.x-1.x issues in this issue queue, Feeds Tamper can be installed with Composer and the testbot can run tests for Feeds Tamper. We can decide later if we use github instead of the Drupal issue queue as our central development station for the Tamper project if Eric feels more comfortable with that. For now we just mirror the two repo's.

Additionally, I've made @ericgsmith a (co-)maintainer of this module.

ericgsmith’s picture

Nice :)

I'm happy with using drupal.org as the primary source for issues and development - will hopefully increase visibility for people wanting to contribute some of the plugins.

ericgsmith’s picture

Issue summary: View changes
ericgsmith’s picture

Issue summary: View changes
scott.whittaker’s picture

Great work guys!

I need to map the same CSV column to two different fields, rewriting that field differently. I can do the rewrite easy enough with regex replace, but if I attempt to reuse the same input map in 2 fields, there is only one tamper for it, so it can't be configured differently for different mappings. Alternatively I've tried adding the same source name twice with different machine names, in which case I do get 2 configurable mappings and tampers, but only the second one works, and the first becomes null.

A third possibility would be a "temporary target" mapping which was available in Drupal 7 Feeds, but this hasn't been implemented in D8 yet.

Are any of the above methods being actively worked on at the moment? Is there another way to do it, short of duplicating the column in the CSV?

MegaChriz’s picture

@scott.whittaker
It's not great UX, but on the mapping page it is possible to select the same CSV source twice and handle these as if they were two different sources.

Here is how you do it:

  1. Select a target. In the source selection, select "New CSV source..." and type in the CSV column name as you normally do.
  2. For an other mapping target, in the source selection, again select "New CSV source...". Type in the exact same CSV column name. This time though, click the small "edit" link next to the input field to change its machine name.

That's it. You now have two CSV sources pointing to the same CSV column, but under the hood they have different machine names. You can now Tamper them separately.

I discovered this "feature" by accident after I developed the UI for the CSV parser. The machine names were added to avoid possible issues with special characters.

scott.whittaker’s picture

@MegaChriz thanks for the quick reply. I mentioned above that I did try this, but even though I am able to tamper both separately only the second mapping actually works and the first comes out as null.

MegaChriz’s picture

@scott.whittaker
Oops, somehow I missed that part. Note that CSV sources are case sensitive in the D8 version of Feeds. So the source names have to match exactly. If you make a typo, the source will stay null. I think spaces also matter.

If no matter what you try, the first source remains null, then this could be a bug. There is already a patch that touches the code responsible for this feature. See #2997951: Custom mapping source should use value as item getter instead of machine name?. Basically, in that patch, resolving the source selection is moved out of the CSV parser and put in the entity processor mapping code instead, so other parsers don't have to resolve sources on their own.

Side note: in the future, the Tamper plugin "Copy" could also be used to fulfill this feature request. In this case, you would type in a source that does not appear in the CSV at all and then use the "Copy" plugin to take the value from one of the other sources. This Tamper plugin is not yet ported to D8. See #2976172: Copy Plugin.

MegaChriz’s picture

Tamper 8.x-1.0-alpha1 has been released! We can move to beta/rc status as soon as all Feeds Tamper plugins are ported.