This field does not show up in the Feeds Import list of possible fields. I assume this is due to the namespace thing but it would be nice to enable this functionality. I'm not sure how to do this or I would post a patch myself.

Comments

vlooivlerke’s picture

Hi I tried to use some code from the phone module
the file: telephone.feeds.inc


<?php
/**
 * @file
 * Implements Feeds support for telephone fields.
 */

/**
 * Implements hook_feeds_processor_targets_alter().
 *
 * @see FeedsNodeProcessor::getMappingTargets().
 */
function telephone_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
  foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
    $info = field_info_field($name);
    if ($info['type'] == 'telephone') {
      $targets[$name . ':url'] = array(
        'name' => check_plain($instance['label']),
        'callback' => 'telephone_feeds_set_target',
        'description' => t('The @label field of the node.', array('@label' => $instance['label'])),
      );
    }
  }
}

/**
 * Callback for mapping. Here is where the actual mapping happens.
 *
 * When the callback is invoked, $target contains the name of the field the
 * user has decided to map to and $value contains the value of the feed item
 * element the user has picked as a source.
 */
function telephone_feeds_set_target($source, $entity, $target, $value) {
  if (empty($value)) {
    return;
  }

  // Handle non-multiple value fields.
  if (!is_array($value)) {
    $value = array($value);
  }

  // Iterate over all values.
  $i = 0;
  $info = field_info_field($target);
  list($field_name, $sub_field) = explode(':', $target);
  foreach ($value as $v) {
    if (empty($v)) {
      continue;
    }
    if (!is_array($v) && !is_object($v)) {
      $field['und'][$i]['value'] = $v;
    }
    if ($info['cardinality'] == 1) {
      break;
    }
    $i++;
  }
  $entity->{$field_name} = $field;
}

But Feeds is not seeing my new include file, tried clearing the cache but did not bring it up in the feed mappers targets

vlooivlerke’s picture

Hi

This above patch works if you uninstall feeds module and then reinstaal feeds.

Telephone will be available under the mappers.

damienmckenna’s picture

@vlooivlerke: Did you try clearing the site caches rather than uninstalling the module?

vlooivlerke’s picture

Hi I did clear the site cache more than once.

It seems that clearing the cache does not make the new feed.ini page availableto feeds. Only uninstaaland/reinstall makes feed aware on the .inc file in my case. It is anointing.

But at least the telephone feed is now working

adiatis’s picture

I can confirm that #1 is perfect solution.

Add "files[] = telephone.feeds.inc" to telephone.info

After clearing the cache, the telephone field is available.

Will this be added to the module for future updates?

vlooivlerke’s picture

Hi

I was thinking to use

Add "files[] = telephone.feeds.inc" to telephone.info

but inspecting other feed modules I noticed that it did not contain a string like that in the .info file.

Thanks, now I learned something too

damienmckenna’s picture

That info file change wasn't needed when we added Feeds integration to Metatag.

The Feeds module keeps several records in the primary cache table, all that should be necessary is to do a full cache clear.

fullerja’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.75 KB

I rolled a patch with the fix in #1, which worked perfectly for me. I did a registry_rebuild and the importer came right up.

petterw03’s picture

Patch in #8 works like a charm for me. Thanks!

tyler.frankenstein’s picture

Status: Needs review » Reviewed & tested by the community

#8 works for me. FWIW, I see an 'und' hard coded in, which may cause issues for multi lingual sites.

tyler.frankenstein’s picture

Status: Reviewed & tested by the community » Needs work

I jumped the gun on this one a little bit, the patch in #8 works only for creating a new user.

The telephone field value is properly set when creating a new user account, but if the Feed is set to update existing users, the telephone field's value will not be updated properly.

For example, creating a user via a CSV file works fine:

demo,demo@demo.com,1234567890

But when updating that same user via a new CSV file later, the new phone number is not saved:

demo,demo@demo.com,4567890123

Feeds reports that "There are no new users.".

Is there a hook(s) that can be added to the patch to indicate a telephone number is being updated? I've posted a fairly detailed description about this question here, and am looking to contribute to this issue's resolution: http://drupal.stackexchange.com/questions/135269/how-does-feeds-decide-i...

tyler.frankenstein’s picture

After further testing, the patch in #8 works fine for existing users if they did not have a telephone value. But if an existing user does have a telephone value, then the value does not get updated during the import (even if "update existing users" is set).

fullerja’s picture

Status: Needs work » Needs review
StatusFileSize
new1.72 KB

Cleaned up the patch a little bit including the 'und' mentioned in #10. Checked updating and it works for me, make sure that you have a unique field defined in your importer.

I also read on StackExchange that the issue mentioned in #11/#12 with importing for users was resolved.

genjohnson’s picture

The patch in #13 looks okay to me.

I created a Node importer and successfully updated a Telephone field on existing nodes and created new nodes with phone numbers.

fullerja’s picture

I also tested this with a telephone field on a users, using profile2 and feeds_profile2. Creation and updating works for me.

Cale Bierman’s picture

The patch in #13 worked for me.

I created a Node importer and created new nodes with Telephone numbers. I also updated Telephone field values on existing nodes.

genjohnson’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new117.05 KB
new135.48 KB
new25 KB

I just tested patch #13 with a telephone field on users. Using profile2 I added a telephone field to user entities. I used feeds_profile2 along with feeds to create the importer. I used the user name as a unique identifier and made sure that "update existing users" was selected.

Here is a screenshot of my mapping for the user processor:

And here is a screenshot of my settings for the user processor:

.csv files aren't allowed to be uploaded, so I've attached a .xsl version of the .csv I imported.

With this configuration I was able to update the phone number of user demo1 and successfully created user demo2.

Based on this I'm marking as RTBC.

fullerja’s picture

Issue tags: +SprintWeekend2015
kevinsiji’s picture

Imported data into fields collection. Works great.

brandy.brown’s picture

When I run the import from a file, it succeeds, but when I try to run the import using http fetcher, it throws

Notice: Undefined variable: field in telephone_feeds_set_target() (line 54 of /srv/bindings/e224733cdb3f43a0a1f61413eee21e21/code/sites/all/modules/telephone/telephone.feeds.inc).

densolis’s picture

I used patch # 13 to import telephones numbers into a content type / node and it worked fine. I did not check to see if it would update an existing field.

gabriel.achille’s picture

patch #13 works for me for both new field and updated field.

tko’s picture

@gabriel.achille Does it work with multi-valued fields for you? Mine does not.

tko’s picture

Have no time to roll a patch but have corrected #13 to work with multi-valued telephone fields. Replace _feeds_set_target from #13 with the following:

/**
 * Callback for mapping telephone fields.
 */
function telephone_feeds_set_target(FeedsSource $source, $entity, $target, array $values) {
  // Iterate over all values.
  $field = isset($entity->$target) ? $entity->$target : array('und' => array());

  foreach ($values as $value) {

    if (is_object($value) && ($value instanceof FeedsElement)) {
      $value = $value->getValue();
    }

    if (is_scalar($value) && strlen($value)) {
      $field['und'][] = array('value' => $value);
    }
  }

  $entity->$target = $field;
}
gabriel.achille’s picture

I am using a single-valued field, I don't know for multiple-valued field. But i can try your updated patch on my case and see if there is no regression.

osman’s picture

I believe the last line should have been:

$entity->{$target} = $field;
osman’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.76 KB

Here is an updated patch.

I tested with single and multiple field values.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

Works for me.

Joni Haeck’s picture

I can verify #27 works.

galeaspablo’s picture

#27 tested in production, works for me

gauladell’s picture

#27 also worked for me, Thank you.

jaspher’s picture

#27 Works here too.. RTBC?

peterbrazier’s picture

#27 Worked for me but telephone.feeds.inc file was placed into the Drupal root rather than sites/all/modules/telephone

santanudas’s picture

#13, #27 worked for me. Thanks for support.

lpalgarvio’s picture

is a commit and publish scheduled soon?

mellowtothemax’s picture

Hello,

Osman how did you import multiple field values?

regards,

Update: Never mind. Tamper feeds worked for me.

cdmo’s picture

#27 worked for me, sounds like this is RTBC

brayfe’s picture

Confirmed #27 worked for me too. Was able to add a field in the importer and successfully import a telephone number. I think it's ready to roll in!

biigniick’s picture

#27 worked for me after uninstall and reinstall of feeds module.

WorldFallz’s picture

I can also confirm #27 works as advertised. It would be good to get this rolled into the dev snapshot at least. I'm happy to co-maintain if that will help move things along.

megachriz’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/telephone.feeds.inc
    @@ -0,0 +1,49 @@
    +/**
    + * Implements hook_feeds_processor_targets_alter().
    + */
    +function telephone_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
    

    For other modules to easier override the target, consider to use the hook hook_feeds_processor_targets() instead (available since Feeds 7.x-2.0-beta1). See https://www.drupal.org/node/2638830.

  2. +++ b/telephone.feeds.inc
    @@ -0,0 +1,49 @@
    +      $field['und'][$delta][$column] = (string) $value;
    

    To support multilinguality, the field should respect the mapping option "language": https://www.drupal.org/node/2638802. This mapping option is available since Feeds 7.x-2.0-beta2.

osman’s picture

Status: Needs work » Needs review
StatusFileSize
new1.85 KB

Thanks for the suggestions @MegaChriz.

I re-rolled the patch with the suggestions.

joelstein’s picture

Status: Needs review » Reviewed & tested by the community

Works for me, thanks!

zlinedavid89’s picture

#42 worked like a charm. Thanks!

bbc’s picture

#42 worked for me as well. Thanks much!

matthieu_collet’s picture

#42 not working for me :(
i uninstalled / reinstalled feeds 3 times
clear cache
...

still not working

I use it with CRM Core entities, perhaps it's the reason ?

matthieu_collet’s picture

it was related to another issue with CRM core and feeds, problem is fixed now

https://www.drupal.org/node/2549793#comment-11201041

thirdender’s picture

#42 worked for me as well.

rsomaskandan’s picture

#42 worked fine for me.

kumkum29’s picture

Hello,

shortly, have you planned to add the patch #42 in the next version on this module?

yazzbe’s picture

#42 works for me.

feeds 7.x-2.0-beta2
telephone 7.x-1.0-alpha1

anairamzap’s picture

Hey, just a quick note to say #42 is working for me on Telehpone 7.x-1.0-alpha1 and feeds 7.x-2.0-beta2. Thanks osman :)

kbrinner’s picture

#42 worked for me with Telephone 7.x-1.0-alpha1 and Feeds 7.x-2.0-beta2 as well. Did not need to uninstall/reinstall Feeds, only had to clear cache.

marcxy’s picture

"#42 worked for me with Telephone 7.x-1.0-alpha1 and Feeds 7.x-2.0-beta2"

I confirm as well.

erindarri’s picture

Wanted to give some more feedback about telephone feeds. I have three telephone fields (main, fax, toll-free) that could be filled in for a content type. I was using phone module and only getting a single phone number entry out of 200. I assumed it was the module and switched to this one. (I added the patch #42 before trying any feeds, so I can't comment on if the patch helps or not.)

But even with telephone, I was having the same issue--only one entry was getting the data. It turned out that it was the only one that had all three telephone fields filled in. In order to get any of the numbers filled, I had to add numbers for all three fields.

I tried to add only one of the fields in the feed at a time.

I tried to add dummy data and then reimport again trying to clear it out.

I ended up adding dummy data and then removing with VBO, but it was a very strange experience that I wanted to add to the pool of knowledge.

anybody’s picture

RTBC #42. Could you please add it to dev and create a new alpha or beta release?

damienmckenna’s picture

I think the module could use a new comaintainer..

fool2’s picture

#42 works with SQL import. Previously nothing would happen- field would show up in interface and import preview would show a value but no values would be imported into the field/database.

fool2’s picture

So #55 is definitely an issue, I have confirmed it with patch #42. I will investigate further. I think the last field in the bundle (or in the import, not sure) is not being populated no matter what-- so when there is only one field populated, it is the last field so it is skipped.

gisle’s picture

Status: Reviewed & tested by the community » Needs work

Number #55 needs to be reviewed before proceeding.

gisle’s picture

Assigned: Unassigned » gisle

Signing up for this one.

anybody’s picture

Thank you gisle, according to #59 I'd suggest do rewrite the foreach to

foreach ($values as $delta => $value) {

and remove the manual count. Perhaps that may solve one of the problems.

gisle’s picture

Title: Feeds Import Integration » Feeds Import Integration for nodes
Assigned: gisle » Unassigned
Status: Needs work » Needs review
Issue tags: -SprintWeekend2015
StatusFileSize
new2.68 KB
new330 bytes

The patch in #42 works, but only for nodes (not users).

Based upon extensive testing, I do not think it is not possible to make it work correctly for users if there are more than one telephone field in the user profile (see report in #55).

I've created a child issue (#2998265: Feeds Import Integration for the user entity) to solve this specific use case.

However, I believe that the vast majority of use cases only involve feeding into nodes, or into user entities with a single telephone field. So to move this issue forward, I've rerolled the patch in #42 to give a meaningful error message if the use case is not supported. I have not changed anything else. This is intended as an intermediary solution, until the child issue is also resolved.

I've also uploaded a file "test_csv.txt" (rename to "test.csv") for those who want to test feed imports with multiple telephone fields.

Please review.

dbiscalchin’s picture

I've tested the patch #63 with a custom entity type using feeds_entity_processor module. It worked perfectly! Thank you!

gisle’s picture

If you need to import telephone numbers into the user entity (as opposed to nodes), you may want to implement hook_field_user_import_supported_alter and use User Import to import the fields.

For an example of this hook for phone fields, check out the Phone Field. This project already has this hook implemented.

FireHawkX’s picture

Status: Needs review » Reviewed & tested by the community

Just applied patch #63 to latest version and it worked perfectly for me.
Telephone showed up in the import feeds and the import worked too. :)

smustgrave’s picture

Status: Reviewed & tested by the community » Closed (outdated)

Telephone is moving from core so closing old D7 tickets

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.