I'm making a clients profile and a customers profile. Set up all the fields in Clients and cloned it, changed the name to Customers and thought that when I went in to manage fields, the ones from the client profile would be there but it only had 'Add new field' and 'Add existing field' without the other fields that were in the client profile. I'm pretty new to Drupal so perhaps they shouldn't have been copied. Please put me right if this is the case! :)

Comments

scanmaster’s picture

Says this after cloning: Notice: Trying to get property of non-object in profile2_page_own_title()

zkday’s picture

Status: Active » Needs review
StatusFileSize
new1.44 KB

Yes,
I'm working in my project and i have a patch for this issue.

zkday’s picture

Says this after cloning: Notice: Trying to get property of non-object in profile2_page_own_title()

see issue #1210620 at http://drupal.org/node/1210620

Status: Needs review » Needs work

The last submitted patch, 1317446-Cloning_a_profile_type_with_field_api.patch, failed testing.

zkday’s picture

waiting issue #1210620 at http://drupal.org/node/1210620 is resolved, and re-test #2 patch.

zkday’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1317446-Cloning_a_profile_type_with_field_api.patch, failed testing.

zkday’s picture

Status: Needs work » Needs review
StatusFileSize
new1.44 KB

Attach patch!

Status: Needs review » Needs work

The last submitted patch, profile2-cloning_a_profile_type_with_field_api-1317446.patch, failed testing.

zkday’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, profile2-cloning_a_profile_type_with_field_api-1317446.patch, failed testing.

fraweg’s picture

Hello,

is this issue solved?

Best regards
Frank

zkday’s picture

Status: Needs work » Needs review
StatusFileSize
new1.44 KB

Update patch for new dev version ;)

p.s:
@fraweg: I'm working for this issue with my customer. You can test and reviews this patch. ;)

The last submitted patch, Cloning_a_profile_type_does_not_copy_the_fields-1317446.patch, failed testing.

fraweg’s picture

Status: Needs review » Needs work

Hello zkday,

thanks for yor work! This patch does noct change this problem on my system. I had test it with the stable and the dev-version.

Best regards
Frank

zkday’s picture

Hi fraweg,

I was reapply the patch in #13 and retest on my system. This has working for this problem ;).
please reapply the patch in #13 for dev-version, and you retest it. ;)

Thanks,

slashzero’s picture

Thank, the patch in #13 worked for me and saved the day!

fraweg’s picture

Status: Needs review » Needs work

Hi,

Thanks for your work. I will test it the next days...

Best regards
Frank

Edit: The patch #13 does not work for me with 7.x-1.2 . Have I to use the dev version?

devilworks’s picture

Patch #13 worked.
Thanks

zkday’s picture

Status: Needs work » Needs review
Bronislovas’s picture

Tried #13 patching by hand. Works great! Profile2 version 7.x-1.2

areynolds’s picture

Version: 7.x-1.0 » 7.x-1.2

My testing indicates the patch doesn't work. A quick look at the debugger makes it appear that the anticipated bundle machine name value ($profile_type_source->type) is not correctly populated (I see a boolean, not a string).

$instances = field_info_instances('profile2', $profile_type_source->type);

Tested with both 7.x-1.2 and 7.x-dev.

zkday’s picture

Version: 7.x-1.2 » 7.x-1.x-dev

@areynolds, thank you for reviews!

In later version of entity module, function entity_ui_clone_entity is called when 1 entity is cloned, that is reset {KEY_NAME} of entity is FALSE, I will fix this bug in later.

function entity_ui_clone_entity($entity_type, $entity) {
  // Clone the entity and make sure it will get saved as a new entity.
  $entity = clone $entity;

  $entity_info = entity_get_info($entity_type);
  $entity->{$entity_info['entity keys']['id']} = FALSE;
  if (!empty($entity_info['entity keys']['name'])) {
    $entity->{$entity_info['entity keys']['name']} = FALSE;
  }
  $entity->is_new = TRUE;

  // Make sure the status of a cloned exportable is custom.
  if (!empty($entity_info['exportable'])) {
    $status_key = isset($entity_info['entity keys']['status']) ? $entity_info['entity keys']['status'] : 'status';
    $entity->$status_key = ENTITY_CUSTOM;
  }
  return $entity;
}

zkday’s picture

Status: Needs work » Closed (duplicate)

This feature need support in entity, and this is issue: #1513812: When cloning entity, fields are not cloned

areynolds’s picture

Thanks @zkday!

hobbes_vt’s picture

Status: Closed (duplicate) » Needs review
klonos’s picture

Issue summary: View changes
Status: Needs review » Closed (duplicate)

...accidental edit?

hobbes_vt’s picture

Yes, sorry - seem to never have hit submit my original post. I meant to report that it worked for me when I applied the patch a week ago. Strangely enough it seems not working any more. One of the core things changed in my installation was the update to drupal core 7.24 - not sure if this has to do anything with it, but I'm afraid I don't have the time to investigate this too much further and will simply re-create profiles instead of using the cloning option.

hobbes_vt’s picture

The entity patch posted in https://drupal.org/node/1513812 #23 did the trick for my latest configuration - thanks for the work fixing this - very much appreciated!

DrSage’s picture

So I faced with same problem, patch is not work anymore when I'm trying to clone Profile.
So I updated code to make it work.
For me it's work with 1.6 version, also it's clone group pseudo fields.

function profile2_type_form($form, &$form_state, $profile_type, $op = 'edit') {

if ($op == 'clone') {
$form_state['profile_type_source'] = clone $profile_type;
$form_state['bundle_source'] = arg(4);
$profile_type->label .= ' (cloned)';
$profile_type->type = '';
}

function profile2_type_form_submit(&$form, &$form_state) {
$form_state['values']['data']['roles'] = array_filter($form_state['values']['data']['roles']);
$profile_type = entity_ui_form_submit_build_entity($form, $form_state);
// Save and go back.
$profile_type->save();

if (isset($form_state['bundle_source']) && isset($profile_type->id)) {
$bundle_source = $form_state['bundle_source'];
$instances = field_info_instances("profile2", $bundle_source);

foreach ($instances as $field_instance) {
$field_instance['bundle'] = $profile_type->type;
$field = field_create_instance($field_instance);
}

// Integrate with the field_group module.
if (module_exists('field_group')) {
$groups = field_group_info_groups("profile2", $bundle_source, 'form', TRUE);
foreach ($groups as $group) {
$group->bundle = $profile_type->type;
ctools_export_crud_save('field_group', $group);
}
}
}
$form_state['redirect'] = 'admin/structure/profiles';
}

rickj’s picture

This issue is closed, as the solution is in the Entity module.

The patch in this issue (comment #67) resolves the problem.

Apply that patch to Entity and profiles will clone correctly.