0

I've got a content type called 2Wd-Tractor with this structure :

  • Model (node title)
  • Engine
  • Transmission
  • Operational
  • Hydraulic System

Engine field is a custom field implemented using Field Api and it does have these subfields :

  • Make
  • Model
  • Net Power
  • PTO Power
  • Aspiration
  • Power Measured At
  • and ...

After that to make this field visible in feeds mapping hook_feeds_processor_targets_alter was implemented.

Here is the code :

foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance)
{
    $info = field_info_field($name);
    unset($callback);

    if ($info['type']=='uceen2wdtractor')
    {
        //The callback for this field type goes here.
        $callback = 'TARGET_SETTER_FOR_en2wdtractor';
    }

    if (isset($callback))
    {
        $targets[$name] =array(
            'name'=>check_plain($instance['label']),
            'callback' => $callback,
            'description' => t('The @label field of the node.', array('@label' => $instance['label'])),
        );
    }
}

Data is imported to Feeds using json files , An importer is provided with these settings :


enter image description here enter image description here enter image description here

finally this is my json file :

enter image description here

The Problem is no data is stored in Engine field . this is the dsm($node) in hook_node_presave :

enter image description here

4
  • Does your field save ok when creating a node via the UI? Commented Apr 2, 2016 at 19:49
  • @littledynamo yes it does , it is even saved when creating nodes via services module and json application format Commented Apr 2, 2016 at 19:52
  • Can you post your hook_feeds_processor_targets_alter? Commented Apr 2, 2016 at 21:15
  • @littledynamo attached Commented Apr 2, 2016 at 21:40

2 Answers 2

2
+200

There are 3 places where the problem could lie:

  1. Data not being correctly parsed by feeds
  2. Data not being correctly saved by feeds
  3. Problem with the field definition itself

Number 3 is ruled out since fields save correctly via the UI.

Troubleshooting Number 1.

Add a hook_feeds_after_parse to your module and either step through with a debugger or dump the $items array to the dblog:

function mymodule_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) {
  if($source->id == 'ENTER YOUR SOURCE ID HERE') {
    watchdog('My Module', '<pre>' . print_r($result->items, TRUE) . '</pre>');
  }
}

Question: is there a value in the items array for your engine field?

If no: there is a problem in the JSON parser definitions and feeds is not extracting the data correctly.

If yes: if the information exists that you require, i.e. every sub field value exists then the problem is not with the feeds parsing.

Troubleshooting Number 2

This points to an issue with your implementation of hook_feeds_processor_targets_alter. Most likely, the data is not in the correct format for saving. Add some watchdog statements in this function to determine:

  1. Is the callback being fired?
  2. If the callback is being fired then there is an issue with your hook_feeds_set_target implementation. It isn't providing the correct data format to allow the field to be saved. You could add a dpm() statement to hook_node_update and then save a node via the UI. This will show the correct format.
0
1

For troubleshooting data that is not correctly parsed, you can also use the Feeds Import Preview module. This module allows you to see what your source looks like after it has been parsed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.