Drupal 7 - how to set up and translate field collection - drupal

I have taxonomy term with field collection field set to unlimited values. FC contains few texfield, textarea and image fields. FC and it's fields are set to be translated by user.
Taxonomy term is localized - all terms are the same for all languages just that they are translated. I have entity translation turned on for taxonomy term and node but not for FC because it trigers notice about not valid base path.
With this configuration: I create term and save it, after initial creation i can add any number of FCs and save them. On translate form I can then add translations for them. And when saved values remain saved for different laguages.
Problem occures when I create a view with relationship to FC, add FC fields and set contextual filter to termID (showing this view via panel on taxonomy terms). Field language stting is set to current user language. On views preview with manually set termID I see proper result for language in url (en/admin/structure/views..) and correct result if I change language prefix. But on term page it doesn't show anything.
I am using latest dev entiy translation an field collection modules.
I also tried setup with entity translation enabled for FC but again i don't get right output from views.
Where am I doing it wrong? FC setup, multilangual setup or in views. Does anyone have a hint how to make FC translatable?

I retested on clean installation. All this apply for what I described in #9 . Same result but some new/confirmed observations and possible workaround:
There is a bug in FC when translating fields for the first time values are not properly saved:
values are saved but when I refresh edit page, fields exist but are
empty/blank, fields on default language are ok
what really happens: when saving translation of FC fields, they are wrongfully linked to default language and not to translated one, also they don't show up when reopening default language so that they could be deleted. This can be bad if you accidentally catch them in a view as I did (for some time this was misleading me because titles were the same).
possible workaround: when first translating you have to delete values that are copied from default language and save it, then you can enter translated values
ET for FC enabled: same issue and workaround
After creating some content on terms and translating them with workaround, I tried to show them in panels via view.
I created a panel and set selection to taxonomy vocabulary I am using and under content I created "new custom content" in which I included some substitutions - for FC field %term:field_test_fc (this is my test content)
when I change language, values change accordingly to selected language
substitution renders all fields of FC and shows them in correct language
this is why this issue is bugging me… it should work on a view too because if term itself can distinguish between different languages of FC fields so can view via panel
I created view (page) in which I list all FC fields of all terms grouped by term name using relationship of that FC
content does change accordingly to the selected language =)
I created another view (content pane) as above and just added context filter, set it to termID and attach it to panels
view shows only FC fields of language that was used last when saving term. This mean that when editing and saving term in default language, view will only show fields of default language. weird :S
ET for FC enabled: it broke both views (showing fields of all languages everywhere), fixed by adding filter based on FC field: language and setting it to current user language
panels view still didn’t work as expected, but I knew that there was a problem with context filter
what I had to do is to remove validation criteria from context filter ( termID)
After solving last problem, view for panel is working and viewing term in both languages shows correct (translated) FC fields =).
Hope it helps understanding where problems occur and how to go around them. Fix would be nice though =)

Field Collections as a module has not yet been patched to support multilingual well. The debate is whether the field collection itself should be set to language-neutral, allowing the underlying fields to be language specific.
However, the field-collection module by itself does not currently support multilingual. There are a number of patches related to this on Drupal.org, including the following two major patch threads:
https://drupal.org/node/1344672
https://drupal.org/node/1316162
The Lingotek Translation module for Drupal 7 is successful at translating field collections and displaying them because it gets around the limitations of the Field Collection module using a combination of hook_entity_load, hook_entity_update, and a translation process that does not rely on the entity_translation module's UI.

Related

calling of one taxonomy from another taxonomy, so both of them have used in the same content type

Can we call one taxonomy term from another as a parent and child relation for example I need to click on product category and that show me product series page and when I click on product each series that will lead me to actual product detail means node, so I have two taxonomies category and series I am about to click on category to carry me to series page and then to click on series page to carry me to product detail page on the concern series”
no codebase problem
i am expecting that these two taxonomies may be used as i have mentioned in the question summary but, i can't do it so i hope some help in resolving this issue
Let's look at this answer, I hope it will help you.
Taxonomy terms from the same vocabulary filtered and referenced on multiple content types
To do this you’ll need to have the Entity Reference module installed. So get that out of the way quickly with drush dl entity reference -y and drush en entityreference -y if you haven't already.
First up, we need the taxonomy set up.
Let's demonstrate with the help of an image.
You’ll notice that these terms could be more or less grouped into two categories: Transport and Sleeping. One term (couchette) kinda fits both criteria and is there to exemplify the reason for not using 2 different vocabularies to handle the issue. Now we need to technically make the distinction between these terms as well and since they are entities, we can use a field for that.
So we can now go ahead and add a new field to this vocabulary of the type List (text) with whatever widget you’d like (and let’s call the field Type). You should make the allowed number of values unlimited and put the following in the allowed values list:
Edit each term and select the appropriate type. As expected, for the term couchette, you should select both options.
Now that we have our taxonomy squared away, it’s time to create a View that will handle the filtering of these terms. Because if we now add the Tags taxonomy term reference field to our content types in the normal fashion (as it is already present in the Article content type) we’ll be able to select all the terms in the vocabulary for all the content types. And that's not what we want now.
So create a drupal 7/8 View that shows taxonomy terms of the Tags vocabulary - let’s call it Tags Filter. Add 2 displays of the type Entity Reference and a filter of the field we added to our terms earlier. So for instance the first display can show the terms which have Sleeping selected and the other one can show terms which have Transport. Save the View and you can close it.
Now finally we can edit our content types and add to each a new field of the type Entity Reference with a select list widget. For the target type select Taxonomy term and under Entity Selection choose the following: for Mode, go with Views: filter by entity reference view and then select the View in question - one of the two displays which we created earlier. In the picture below, I named one of the displays

How to change entity language in bulk?

I have a site in drupal which is in spanish by default. Now I want to add the english translation. It has a lot of entities "producto" with undefined ('und') language. I want to mass assign the 'es' language to them. Before posting this question I have checked this other question How to change node languages in batches? but I'm unable to accomplish what I want. Let me explain:
a) I have tried Language Assignement but it last commit was 1 year ago and it has a critical bug that can lead to data loss (I reproduced the error too) I also tried with the patch from user barami but the data loss persists.
b) View Bulk Operations: I've tried it, but it does only update the field in database table "node". Not the other ones.
c) So I checked out how the drupal database works and created a sql script which also leads to data loss:
-- Step 1 Node lang
update node set language='es' where type='producto';
-- Step 2 body field
update field_data_body set language='es' where bundle='producto';
-- Step 3 Field comment vody
update field_data_comment_body set language='es' where bundle='comment_node_producto';
-- Step 4 For each field of producto, update language
update field_data_field_precio set language='es' where bundle='producto';
update field_revision_field_precio set language='es' where bundle='producto';
(...)
I have the following translation modules activated:
Internationalization, Block languages, Field translation, Menu translation, Multilingual content, Multilingual select, Synchronize translations, Taxonomy translation, Translation redirect, Translation sets
What Am I doing wrong with my sql script? Are there other plugins to accomplish what I want to do? Any suggestion will be appreciated Thanks!
Here's how I bulk set the language on my site:
Using Views Bulk Optimization, select all nodes you want to change, use the 'Change value' option and then change the value to language you want.
After you've done this, the field values will not appear when editing the nodes, so you need to run a script, e.g. UPDATE database.field_data_body SET language='en' WHERE bundle='page' (use your db name, field name, and bundle as appropriate).
IMPORTANT: If you have any custom url aliases, they will be overwritten with this approach, due to a problem with pathauto, but there's a work-around: first go to /admin/config/search/path/settings, and change the 'Update action' option to 'Do nothing. Leave the old alias intact.', then change this value back once you've run your Views Bulk Operations action.
Assuming you can make a view listing your entities, you can use the Views Bulk Operations module to do this. I just explained how to do this the other day for nodes on Drupal Answers.
Another solution would be to just execute the first SQL because I have discovered that the fields language must remain 'und'.
update node set language='es' where type='producto';

Error in copying the content of a cck field between 2 nodes using cck computed field

I have two content types (job_post and job_application) linked using the node reference + node reference url nodes. When I click a link in a job_post node, a new job_application node is created, so that candidates can fill out their job application. My goal is to automatically copy the content of an cck email field from the referenced job_post node to a cck email field in the job_application node.
To achieve this, I am trying to use a cck computed field, as suggested in: http://drupal.org/node/298951.
In my computed field I have placed the following code:
$node_field[0]['value'] = db_result(db_query("SELECT field_emailfieldjobpost_value FROM content_type_job_post WHERE nid=%d",$node->field_referencefieldjobapplication[0][nid]));
where the field_referencefieldjobapplication, is the node reference field in my job_application node.
In the display format box of the computed field I have:
$display = $node_field_item['value'];
I have selected the option to store it in the database as a varchar.
However, nothing seems to happen. I never see the cck field or its content both when I create or after I save a new job application (I have even tried to see it in views and failed). Any suggestion on what might be wrong?
Thanks
What I would do, is give a parameter with the link (the id of the job_post). and catch the parameter and place it in a disabled cck field.
Then write a module using the hook_node_api when a jobapplication is saved, you get the data from the job_post (using node_load) and use the data from the job-post however you want.

Drupal Views: Get nodes with the same taxonomy as the current node

I have a Content-Type with taxonomy-terms. It's a select-list, so it can have only one taxonomy - at least of that vocabulary. Now I need to build a view that lists all nodes with the same taxonomy.
Thought that this wouldn't be too hard since it sounds pretty basic. Yet I can't get it working. Any ideas? I'm trying to avoid writing a module for this.
While this was technically possible with Views 2 as described in some of the other answers, Views 3 has this integration built in.
You can create an argument for the taxonomy term id and then choose "Provide default argument". This will then give you an option for "Taxonomy Term ID from URL" and "Load default argument from node page..."
This will allow you to take the taxonomy of a page and pass that as an argument to your view block.
Note: Views 3 is currently in Alpha 3 but in my experience is at a relatively stable state and I am using it on production sites. If it has features like the one above that you find useful please use it, test it and submit bugs/patches if you encounter any issues!
This answer works in Views version 2 or higher. First you need to install Views attach ( http://drupal.org/project/views_attach ). Please read about Views attach before proceeding further. Views attach is best explained by this video http://mustardseedmedia.com/podcast/episode37
Now we get to Views attach. Please enable the views attach module before proceeding. Essentially Views attach attaches a view at the end of the node. In our case our view will be a listing of other articles with the same term.
We will essentially need to "pass" the taxonomy term of the node to the view. Let the name of your Vocabulary be called MyVocab.
Steps to make the view.
Lets call the view display_other_articles_with_same_taxonomy.
Add a display of type Node Content (available after enabling Views attach). This is a display just like block and page displays but with special ability of attaching itself to the node.
Make the following settings in the Node Content Display
Node content settings
Node types: [select the content types you are interested in seeing the list of nodes with same taxonomy term]
Build modes: Teaser, Full node
Arguments: token
Show title: No
You should select Use tokens from the node the view is attached to under Arguments. Let the token be [term-id] This is the "ID of top taxonomy term". This is very important!! Essentially you are going to be passing the taxonomy term of the node from the MyVocab (See http://groups.drupal.org/node/11788#comment-38332). If it has the lowest weight, the taxonomy vocabulary will be the first vocabulary in the taxonomy section of your node edit form. Add an argument Taxonomy: Term Id.
Add the fields you are interested in e.g. Node: Title. Make sure the Node: Title is made into a hyperlink by ticking Link this field to its Node
So what this view is going to do is:
Take the taxonomy term from the MyVocab vocabulary in the Node that is currently being viewed
Pass that as argument to the view display_other_articles_with_same_taxonomy
List all the nodes that have the same taxonomy term as the node being displayed.
Thats it!
If you're using Views 3 (currently at alpha3 at the time of writing) and you want a block (right now the articles have same taxonomy term come at the end of node body) you can do it in the following fashion:
Forget about views attach... its not required
Add a block view. It should contain the same argument, fields and filters as the instructions above for the Node Content display.
You need to modify the settings for the argument Taxononomy: Term Id just slightly: Under Action to take if argument is not present: choose [x] Provide Default Argument. Choose [x] Taxonomy Term ID from URL. Now make sure [] Load default argument from term page is unselected and [x] Load default argument from node page, thats good for related taxonomy blocks. Also [x]Limit terms by vocabulary and choose the Series vocabulary.
Make sure you name the block and put it in the appropriate region.
Note: This answer is subset of the answer I provided at How to just show NodeQueue block on included nodes? In that scenario the requirement was that the related articles are explicitly selected and listed in a particular order. Its a little more complex and uses Nodequeues which we don't need here at all.
Use relationships
Node 1 -> Relationship 1 -> Term // This will be relationships->taxonomy->term
Term -> Relationship 2 -> Node 2 // This will be relationships->node->node
Argument NID to filter NODE 1
Fields or node full view on Relationship 2 (you will see select box on field adding form, to determinate what NODE to use)
Views gives you the options to add filters. Click the plus sign in the filters area of the views admin UI, select Taxonomy from the list, check either Term or ID, and fill in the value that you need to filter by.
EDIT (for explicit instructions):
First, add the necessary fields that you want under the fields section that you want to display from the nodes that you are trying to filter such as node title, etc.
Under Arguments, click the plus sign and select Taxonomy
Check Taxonomy: Term and click Add
Click Update
In your preview area test it out by adding an argument and clicking preview. If it doesn't work, your nodes do not have attached taxonomy, your views module is corrupted, or you didn't follow directions.

View of Terms. How to get term synonym in Fields or via Custom field (php code)?

I am using Drupal 6, and Views 2.
For example, term has the alias “vocabulary/term1” (only one level, no nesting).
How do I obtain “term1” field for every item in View, displaying items of type Term?
The probably best/easiest way is to use the token of pathauto.
If you build links use the "output this field as link" feature, which converts the links to it's aliases automatically

Resources