I'm working on existing site which has small boxes with an image, title & text in them multiple times on a page. Currently it uses fields for each one so there'll be six image fields, six title fields, etc but I'd like to making them all one field in a field collection which can be added multiple times.

Creating the new field collection an appropriate fields is fine but what is the best way of moving the existing multiple field images, titles, etc to the field collection?

  • you mean you don't want lost fields data?
    – Yuseferi
    Commented Mar 28, 2017 at 12:05
  • @zhilevan yes, I'd like to transfer the data from the current fields E.G field_image1, field_image2, etc into just the new field_image_collection which will be a repeatable field.
    – Neil Nand
    Commented Mar 28, 2017 at 12:18
  • I did something like that 2-3 years ago, but it needs some custom code and at this time I don't have active drupal 7 with Field_collection and data to test it :(. just could give you a summary of the solution.
    – Yuseferi
    Commented Mar 28, 2017 at 20:37
  • @zhilevan A summary would certainly be helpful as I currently only have a vague idea that it'll either involve using the fields API or a fair amount of SQL (which probably isn't the recommended way).
    – Neil Nand
    Commented Mar 28, 2017 at 20:40
  • ok, how many nodes do you have in that content type?
    – Yuseferi
    Commented Mar 28, 2017 at 20:42

1 Answer 1

  • Create your Field collection,
  • Add new fields to it
  • Add field Collection Field To your content type

  • Create a Custom module ( if you don't have)

  • With Getting help of Batch Operation Docs, Create A Batch Operations on your desired content type

  • On each epic load node, get your fields data,
  • Add those values to field collection ( add an item at field collection programmatically)
  • Check the Results
  • remove old fields from the content type

I Strongly Recommend befor write batch, try it on one node, I mean create a route ( I mean item with hook_menu) then in call back try to achieve what you want, after success convert it to a batch operation or do it with VBO + Php Filter module(instead of batch processing)

  • I'm going to read through the documentation and see if this will do what I need, thanks for the answer.
    – Neil Nand
    Commented Mar 30, 2017 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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