Not your fault, as I've looked at the code, but it's a shame I guess that when it's run there is not a lot of context information around to pull from.
I'd hoped to be able to have access to the target destination field definition already,

(My use case is trying to rewrite an imported string into an entityreference reference ID, and if I knew the target field definition info I'd be able to do the lookup better)

but I guess I have to do all those api lookups by hand. :-(

I was able to push the module here to give me the 'source' and the 'settings' arrays ... but not the target info.

No action needed here, just a little comment from me.


meSte’s picture

Status: Closed (works as designed) » Active

Having to set a default value for empty fields based on another field, I modified as follow:

function feeds_tamper_php_callback($source, $item_key, $element_key, &$field, $settings) {
  $field = feeds_tamper_php_value($settings['php'], $field, $source->items[$item_key]);

function feeds_tamper_php_value($code, $field, $item) {
  $code = eval($code);
  return $code;

to expose the whole $item array.
I think that exposing a more generic object, such as $source, would kill performance with large files.

Tested with a very small 13 cols x 23 rows csv file: worked fine.

I hope this could be useful.

tema’s picture

Title: Handy. Too bad it's so limited. Wish we had more context available. » Full item context access needed
Component: Documentation » Code
Status: Active » Needs review
690 bytes

+1 for this change. Tested with relatively small web-scraping. Works good to me. No significant performance drop was expected.

gaurav.goyal’s picture

Great Work. Tested with a 5579 rows X 9 cols CSV, works fine. only having some @docblock missing issues will submit the patch after some time

gaurav.goyal’s picture

Here is the Patch.

vegantriathlete’s picture

Status: Needs review » Needs work

Took just a cursory look at the patch.

+++ b/plugins/php.incundefined
@@ -19,21 +26,31 @@ function feeds_tamper_php_form($importer, $element_key, $settings) {
+    '#description' => check_plain('This code will be executed. Use $field as value of this field. Do not use < ?php and ? >. <br />For example, use:      return substr($field, 0, 10);'),

Definitely disagree with changing t() to check_plain()

meSte’s picture

Just released 1.1 with this feature.

meSte’s picture

Issue summary: View changes
Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.