Thanks for creating this module. I'm just getting into it today, and hoped you might help me out with how to pursue this task.

  • I have a content type called store
  • It has a field_store_address of type addressfield
  • It has a field_location of type location

I am trying to copy the postal from the addressfield to the postal code on the location field. So I'm not sure how your command requires me to tackle the field names?

This is an entity(node) and a bundle(store) but I don't know the syntax for the addressfield and location.

Would it be field_store_address:postal_code and field_location_postal_code?

Thanks for the insights!

CommentFileSizeAuthor
#3 field_data_copy.drush_.inc_.zip3.06 KBbroon
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pontus_nilsson’s picture

Sorry, this module can't help you with that. This module assumes you copy values from a field with the same type as the target field type.

Although, if you have time and patience :) You could try altering the code in the function at the bottom where it fetches the value.

magicmirror’s picture

Status: Active » Closed (works as designed)

Thanks for the info. I'll take a look at the structure and evaluate what I can do coding wise!

broon’s picture

Status: Closed (works as designed) » Needs review
FileSize
3.06 KB

In some cases I need to convert fields as well. While this is pretty easy for converting text to textarea and vice versa, it indeed need some adjustments for other conversions. Also, one need to check, if cardinality of source and target field are compatible.

I extended the module to enable also field conversions. While default syntax is

drush fieldcopy field_a field_b bundle_name(opt) entity(opt) entity_id(opt)

there's now a new drush command to convert fields:

drush fieldconvert field_a field_b conversion_type bundle_name(opt) entity(opt) entity_id(opt)

Simple conversion types that are included in my adaptation are "text2textarea" and "textarea2text". Both text and textarea share the same value structure, so this is fairly easy. The third conversion type I added is "entity_reference2text", which copies the title of the referenced entity to a text field. Also still pretty easy, but of course requires some more code lines.

Since I have now two commands, I moved some of the checks that run first into a common function. In that function I also added a check for the fields' cardinality to ensure no data is lost (for both copy and convert command).

I would think that makes a great addition to the module and can now easily be extended for other conversion types. I am still working on further extension to meet my current needs. If you are interested in my custom conversions, just let me know. In any case I am marking this as needs review as this might find a way into the official branch.

Cheers,
Paul

ps. Is there a reason why the folder is named "field_value_copy" while the drush file is called "field_data_copy.drush.inc"? It's probably due to renaming along the development process, I guess.

Summit’s picture

Issue summary: View changes

Hi,
Will this module be finished somewhere in the near future?
Greetings, Martijn

pontus_nilsson’s picture

There is no planned development. I see this module as a proof of concept using the Entity API and Drush.