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:

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
Comment #1
Sorin Sarca commentedHi,
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.
Great, save the fields and go to Edit filters. For vid field add a new filter:
Name: Get vocabulary id
Function: ::getVidFromName
Params: [field]
Save filters and import should work.
If any problems, just let me know.
Comment #2
rafaelcaceres commentedHi Sorin, thanks for the response!
I don't have "Vid", just "Vocabulary".
I've tried, but the issue is the same 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?
Comment #3
rafaelcaceres commentedTo solve, I did this time at feed_import.inc line 1463
I know this is not an elegant solution, but works...
Comment #4
Sorin Sarca commentedThis 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.
Comment #5
rafaelcaceres commentedHi 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.
Comment #6
rafaelcaceres commentedComment #7
Sorin Sarca commentedThe ::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.
Comment #8
dragon658 commentedHello, 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
Comment #9
Sorin Sarca commentedFixed it right now, should be in dev version.
This is my fault, will be changed soon to machine name.
Ask people who made Drupal :P
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:
So in the end:
Juice will be in Drinks vocabulary and Pie in Food vocabulary (this decision was made on runtime).
Comment #10
dragon658 commentedOk, thank you for your explanation, Sorin!