I'm updating some old Drupal 7 sites, and I need to merge a number of fields across multiple content types.

For example, I have the field_article_body, field_page_body, and field_event_body fields that needs to be merged into the core body field, or the field_article_image, field_page_image, and field_event_image fields that need to be merged into the field_image field.

I am hoping there is some solution which can assist me in combining these fields, or alternatively some SQL magic which an expert can help me with.

Do you have any idea?

up vote 5 down vote accepted

By using Views (to build a list of nodes to be updated) and a combination of Rules and VBO (to mass update such lists) you should be able to perform the merge of those fields.

Refer to my answer to "How to bulk update select list fields?" for an example with way more details about that, which is about a variation of your scenario (ie change the value of an existing field, while you want to "copy" the value of an existing field to the value of a new field).

For your case, this example of a Rules Component (in Rules export format) should be close to one of the Rules Components you'd need for your "field_image":

{ "rules_set_an_initial_value_for_image_field" : {
    "LABEL" : "Set an initial value for image field",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "node" : { "label" : "Node", "type" : "node" } },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_article_image" } }
    ],
    "DO" : [
      { "data_set" : { "data" : [ "node:field-image" ], "value" : [ "field_article_image" ] } }
    ]
  }
}

Note: by using an approach with modules such as above (instead of SQL magic), you do have the advantage that all possible relatic magic will happen automagically and behind the scenes (eg: create a new revision of such nodes). And it avoids your Drupal database gets corrupted because "you forgot some table".

  • 1
    Thank you. This was just the answer was looking for. The video mentioned in your linked answer has moved to drupalize.me/videos/using-rules-components-vbo?p=1157 – MrPaulDriver Aug 30 '17 at 13:55
  • 2
    Merci (oeps: thank you) @MrPaulDriver, for the accept, and +1 ... About the video in the linked answer: it can also be found at "Using Rules components with VBO", where it is located including the correct attribution to famous "Johan Falk" (together with dozens of similar links to other commonly known videos from the same author, about Views, Flag, etc). – Pierre.Vriens Aug 30 '17 at 14:28

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.