I created a taxonomy import from JSON file. When trying to process, I got this error:

The website encountered an unexpected error. Please try again later.

When I map my static field to the right vocabulary, I only have a vocabulary field type, as I show in this image:

screenshot 1

This options came from entity_get_property_info and are used to get properties from entities. So, when I try to process, things look like this:

Array ( 
  [vocabulary] => 7 
  [language] => und 
  [name] => Operations 
)

But when the proccess try save this entity, taxonomy_term_save expects [vocabulary] to be [vid]. I change the entity value before save and works like a charm.

if($this->entityInfo->name == 'taxonomy_term' && isset($entity['vocabulary'])) {
   $taxonomy_term = taxonomy_vocabulary_machine_name_load($entity['vocabulary']);
   $entity['vid'] = $taxonomy_term->vid;
}

I made this way so I can set machine name and don't need to worry about deploys.

This is a real problem? Or maybe something in my enviroment?

thanks

Comments

Sorin Sarca’s picture

StatusFileSize
new21.17 KB
new15.13 KB

Hi,

the images doesn't show available options (except tid). You should select the vid option which stands for vocabulary id, which must be a number. Because in this case the id can be different in other drupal instance, using vocabulary machine name is more practical for reusing feed configurations. There are more ways to do this, but I'll show you the one that can be made only from UI:

first, remove the vid (or vocabulary) from static fields
second, go to edit fields (not static ones) and add vid field. Leave empty the Paths options, for Action when filtered result is empty select Provide a filtered default value and for Default value use the vocabulary name or machine name, for example Tags.
Feed Import VID field

Great, save the fields and go to Edit filters. For vid field add a new filter:
Name: Get vocabulary id
Function: ::getVidFromName
Params: [field]

Feed Import VID field filter

Save filters and import should work.

If any problems, just let me know.

rafaelcaceres’s picture

StatusFileSize
new41.39 KB
new14.9 KB

Hi Sorin, thanks for the response!

I don't have "Vid", just "Vocabulary".

feed fields

I've tried, but the issue is the same error.

error

You have this field, and the module gets it from entity_get_info, so this function return different things. What version of feed_import are you using?

rafaelcaceres’s picture

To solve, I did this time at feed_import.inc line 1463

<?php
if($this->entityInfo->name == 'taxonomy_term' && isset($entity['vocabulary'])) {
  $entity['vid'] = $entity['vocabulary'];
}
?>

I know this is not an elegant solution, but works...

Sorin Sarca’s picture

This is interesting... What entity are you using? You can found the entity name in Edit Feed tab or in the feed import listing page.

If the entity is Taxonomy term (taxonomy_term) then all is ok.

You can manually add the vid field by unchecking "Use defined fields". Repeat the procedure explained in the comment above for field vid (added manually).

LE: Don't forget to comment out the changes you made in source code.

rafaelcaceres’s picture

Hi Sorin,

You are right, I add vid unchecking the "Use defined fields" and works (without the code)! The filter still not working, but it is another issue.

Thanks a lot.

rafaelcaceres’s picture

Status: Active » Closed (fixed)
Sorin Sarca’s picture

The ::getVidFromName() expects as param the vocabulary name not the machine name (I know is not so good, this will be changed).

If you are planning to import a lot of taxonomy terms consider using a Pre-process callback. In UI add the static field vid with desired machine name (or name) and in pre-process callback just set the vid to corresponding id of machine name (or name). This way the vid will be already known.
Anyway the ::getVidFromName() caches the vid so it won't take long time to execute, but sometimes little things can speed up a large process.

dragon658’s picture

Hello, Sorin!

Thank you for this "Feed Import" module, it is much better than popular feeds module. (in my opinion)

Today I downloaded 7.x-3.3 version of this module, created vocabulary and tried to import data to this vocabulary.
I also got the problems described by rafaelcaceres:
1. I could't find "vid" on "Edit fields" page.
2. I was forced to put vocabulary name (not the machine name) for "Default value" field.
Is it normal, or is it a bug?

Also I have a question: why is it so much difficult to specify taxonomy term vocabulary?
Is it theoretically possible to select vocabulary with select list on "Edit feed" page?

Denis

Sorin Sarca’s picture

1. I could't find "vid" on "Edit fields" page.

Fixed it right now, should be in dev version.

2. I was forced to put vocabulary name (not the machine name) for "Default value" field.

This is my fault, will be changed soon to machine name.

Also I have a question: why is it so much difficult to specify taxonomy term vocabulary?

Ask people who made Drupal :P

Is it theoretically possible to select vocabulary with select list on "Edit feed" page?

Yes and no.
It is possible but then you will be forced to import in only one vocabulary. The way it is now, you can import in multiple vocabularies.

Consider the following example where I map name to taxonomy term name and category to vocabulary:

[
  {
     "name": "Juice",
     "category": "Drinks"
  },
  {
     "name": "Pie",
     "category": "Food"
  }
]

So in the end:
Juice will be in Drinks vocabulary and Pie in Food vocabulary (this decision was made on runtime).

dragon658’s picture

Ok, thank you for your explanation, Sorin!