How to change entity language in bulk? - drupal

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';

Related

Get Requsition ID based on PO

In FSCM I am looking to modify the Search view on Add/Update PO page (Main Menu--> Purchasing--> Purchase Orders--> Add/Update POs) to display the Requisition ID associated with the PO in the search results page. The only table I have found that has both PO_ID and REQ_ID is PS_PO_LINE_DISTRIB however unless I use a SELECT DISTINCT clause I will get multiple PO_ID rows when there are more than 1 line on a PO.
Within Purchase Order Inquiry you can see the related Requisition ID's related to a PO by clicking on Document Status link inside the Purchase Order inquiry details page.
I started looking at the PeopleCode within the the Purchase Order Inquiry to see how they are linking the PO to a Requisition and it appears to use work tables with related PeopleCode function libraries, but I wasn't able to figure our how they get linked. I am hoping someone else may know the answer to this. Thank you.
I'm on an old version of PeopleSoft (SCM 8.80, Tools 8.51), so your mileage may vary. I'm assuming you're familiar with App Designer. If not, comment below and I'll add some details about what I'm clicking on.
Find the name of the Add/Update PO component.
Open the PURCHASE_ORDER component in App Designer. Now let's find the name of the search record. Note that there is a different record for the Add Search Record, so if you want to change that too, do all of this for that record as well.
Open the PO_SRCH record, and add the REQ_ID field to it. Make sure you mark the field as a key. You should consider saving your modified PO_SRCH under a new name in case you want to be able to revert to vanilla PeopleSoft. If you do, change the Search Record in the component to your new record name.
We can see that PO_SRCH is a view. So let's modify the view to pull in REQ_ID from PO_LINE_DISTRIB. As you mentioned above, there doesn't appear to be another table with both PO_ID and REQ_ID, so you'll have to do a SELECT DISTINCT.
We should do a LEFT OUTER JOIN instead of a standard join because if you do a standard join and you enter a purchase order with no lines and save it, then you'll never be able to retrieve that purchase order in this window. Since REQ_ID is a key field, we can't have a null, so we have to do the CASE.
One odd thing that I ran into here was building the view now gave me an error about selecting fewer columns in the SQL than I had in my record definition. I solved it by modifying the view for SQL Server. I've never had to do that before and I don't know why I had to do it for this specific record. But anyway, I entered the same SQL under the record's "Microsoft SQL Server" definition.
In the properties of PO_SRCH, we can see that it has a related language record. If you're only using one language, you can probably get away without changing this, but I'll do it for completeness. Open PO_SRCHLN. Now add REQ_ID to it (mark it as a key field like you did above), and save it as PO_SRCHLN2 (I'm saving it under a new name so I don't break anything else that may be using PO_SRCHLN).
Edit the SQL the same was as you did above. Note: I didn't have to also change the Microsoft SQL Server definition like I did above. I have no idea why.
Now build PO_SRCHLN2.
Go back to PO_SRCH and change its related language record to PO_SRCHLN2.
Now build PO_SRCH.
Hopefully you didn't get any errors and your search page has the requisition ID in it now. My system doesn't use requisitions so they're all blank in the example below, but the new field is there.

Drupal 7 - how to set up and translate field collection

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.

Multiple input fields in table

Currently we are migrating our intranet from plone 2.5 to drupal 7. Everything works out pretty well except one problem we are facing with the cck module.
In plone we had one content type "application" which allowed our members to applicate for a specific project. There were many input fields for describing the required qualification from other projects like in the following "image".
project description
[ ][ ] + - up down
[ ][ ] + - up down
[ ][ ] + - up down
add new row
Our member had the possibility to mention an unlimited number of projects and associated descriptions.
So the problem is, i´m unable to do anything similiar in drupal 7.
I could definitely add an unlimited node reference field and an unlimited text field, but there would not be any kind of relationship between the two fields and the user would have to click "add another entry" twice.
Another option would be the use of the module http://drupal.org/project/tablefield but its not possible to use the first column as a node reference.
I´ve browsed through every cck module available and found nothing really helping, so now i hope you can help me!
Thank you
Have you tried the field collection module?
This helps you add a collection of fields as a single field.
So you could have 'Projects' as a "field collection" type field have unlimited number of values. You can then add the individual field like the Project name, description, etc. in the field collection.
This module is for D7.
New answer to an old question (but isn't that how Drupal usually works): you might want to try the Multifield module as an alternative to Field Collection or the other solutions posted here. It's meant for this type of problem.
The module Field group is creating this relation for you.
In Drupal 6 we can do this using Flexifield The project description page of flesifield says that similar functionality can be achieved in Drupal 7 using Combo Field. But I have never tried it though. It might worth giving a try.
For Drupal 8 you can also look into the Paragraphs Module for handling a multiple field with multiple inputs. Can be used for product properties, recipes and more advanced use case where a single field can behave like a content type.
There is also a module for Drupal 7 and Drupal 8 called Double field

Drupal view to list nodes and comments

I want to create a view that shows the latest posts in a forum and also any latest comments. The comments and the posts would all show in the same view. Is it possible for me to do this?
Thanks in advance,
Ben
In essence: no. Views requires you to choose one main resource in the first step: you there (amongst others) choose to go with either nodes, or comments.
However, with some (ugly) configuration, you can load the comments that go with nodes. Each result would look like, Node - Comment, e.g.:
Can I have cheesburgers - First!
Can I have cheesburgers - No, I was first!!!111oneone
Can I have cheesburgers - LAME.
and so on. With some styling, you can then get it to show comments and nodes in separate rows.
However, this is ugly and hackish. My advise: write a simple module that either exposes a block, or a menu+page, and do two simple (and light) queries on the database: SELECT nid, title, ... FROM {nodes} LIMIT 10 and SELECT nid, name AS title, ... FROM {comments} LIMIT 10 then mix these two up. Or, with some (more complex) SQL magic, you could even join the two tables and create fancy results that e.g. order by created date of either nodes or comments.
With Drupal 7 you can add a relationship Last comment and then add that field to the view.
One idea I've seen is to use Views Custom Field to "attach" a wholly separate view with PHP code. See comment #4 for the code (in a request for this feature in Views. for a code example).

Drupal Custom CCK field with multiple child fields

Is there a way of creating a composite field that can have multiple values, with each value having another group of composite values?
E.g. we want to have this structure at the end:
Group 1 (unlimited number of groups)
Child field (unlimited children for each group)
Child field
...
Group 2
Child field
Child field
...
...
Is this possible at all for a custom module that defines a CCK field? If so, can someone push me in the right direction?
this is a very know and debated issue in the drupal world.
this feature is called cck "multigroup" and it looks it's pretty difficult to implement.
there are a lot of posts in the drupal forum about this, i suggest you to start here:
http://drupal.org/node/494100
it's a kind of "hidden" feature in the cck module. looking in the module directory, you will find instructions here:
cck/modules/content_multigroup/README.txt
Edit: Ongoing work on the multigroup module has moved to the experimental
CCK 3.0 branch.
in the meantime you can try to deal with it using the flexifield module
(but it's kinda hackish, i won't use it in production)
I ended up creating my own "Cost/Product" CCK compound field based on this excellent tutorial with example modules: http://poplarware.com/es/articles/cck_field_module
I haven't figured out yet how to pull out a specific sub-field, such as cost, in Views. I only get the entire ": $" compound.
For Drupal 7+, you probably want to check out the Field collection module, or Field group if multiples aren't necessary.
This issue is pretty old, but I just happened across it. I would think the way to handle it for now would be with a second cck type for the children, and the groups as a node_reference field. So you'd have:
MasterType
group field
unlimited per node
each one, a reference to a ChildType node
ChildType
child field
unlimited per node

Resources