When you clone an entity it maintains the original author. I'd like to let users clone other users entities and modify for themselves. Is this possible? Or can someone point me in a direction via code?

Thanks

Comments

thronedigital created an issue. See original summary.

emek’s picture

You can subscribe to the POST_CLONE event and update the author to the one that is logged in.

  public static function getSubscribedEvents() {
    $events[EntityCloneEvents::POST_CLONE] = ['updateClone'];

    return $events;
  }

  public function updateClone(EntityCloneEvent $event) {
    $clone = $event->getClonedEntity();

    // Set UID to current user.
    $clone->uid = \Drupal::currentUser()->id();
    $clone->save();
  }
BerndB’s picture

Automatically changing the author on cloning will be required to give the user full access.
Otherwise you have to change the author manuelly as administrator.

Please make this a part of the settings of this module - this would really help a lot!

maticb’s picture

Status: Active » Needs review
StatusFileSize
new8.43 KB

I've added a patch with the following concept behind this:
- I add permissions "allow user to take ownership of cloned entity" to all the content types that have the ownership trait (meaning they can have owners)
- If user has this permission he will see a checkbox on the clone form, if ticked, the owner will be changed to drupal's current user.

* Note: patch will only apply to the latest dev version, because of some other changes on the form in a commit before. Doesn't apply to beta 3.

maticb’s picture

StatusFileSize
new8.43 KB

Reuploading patch because of a copy&paste mistake when creating patch.

bcizej’s picture

Version: 8.x-1.0-beta3 » 8.x-1.x-dev
StatusFileSize
new10.21 KB

There were some issues with the patch, clone form was checking for incorrect permissions based on entity bundle instead of type.

I also fixed the TypeError with injected AccountProxyInterface service, replaced deprecated FILE_EXISTS_RENAME constant and minor fixes to method descriptions.

nace_fr’s picture

Status: Needs review » Reviewed & tested by the community

I have applied and tested the patch. It applied without errors and worked as described from maticb. I'm changing status to "Reviewed".

matthiasm11’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new5 KB
new12.68 KB

Added an extra checkbox to the entity_clone settings:
Whether the "Take ownership" option should be checked by default on the entity clone form.

nace_fr’s picture

Status: Needs review » Reviewed & tested by the community

Hi. I have also applied and tested patch from #8. It applied without errors and worked as described. I'm changing status to "RTBC".

andreymaximov’s picture

Rerolling #8

colan’s picture

Category: Support request » Feature request
Status: Reviewed & tested by the community » Needs review

I'd have more confidence in committing this if someone could test the reroll.

colan’s picture

Status: Needs review » Needs work

I had changed my mind and was about to merge this because tests are passing, but then I noticed the code duplication. EntityClonePermissions::entityTypeHasOwnerTrait() is basically identical to EntityCloneForm::entityHasOwnerTrait(). Why not simply have the latter just get the type and then pass it to the former? There's no need to duplicate the entire thing.

guilhermevp’s picture

Assigned: Unassigned » guilhermevp
guilhermevp’s picture

Assigned: guilhermevp » Unassigned
Status: Needs work » Needs review
StatusFileSize
new8.31 KB
new14.88 KB

Status: Needs review » Needs work

The last submitted patch, 14: 3078811-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

guilhermevp’s picture

Status: Needs work » Needs review
StatusFileSize
new2.99 KB
new14.93 KB

Updated patch.

luiscarvalho’s picture

Status: Needs review » Needs work

Hello, I just tried applying the patch #16 with

git apply 3078811-16.patch

and it failed with the following errors:

error: patch failed: src/EntityClone/Content/ContentEntityCloneBase.php:32
error: src/EntityClone/Content/ContentEntityCloneBase.php: patch does not apply

I believe it needs a reroll.

suresh prabhu parkala’s picture

Status: Needs work » Needs review
StatusFileSize
new15.09 KB

Re-rolled patch.

guilhermevp’s picture

StatusFileSize
new13.19 KB

Re-rolled patch, please review. It's basically the same that #18 re-rolled, but I renamed some classes for clarity.

Status: Needs review » Needs work

The last submitted patch, 19: 3078811-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

guilhermevp’s picture

Status: Needs work » Needs review

Needs review for #18

adalbertov’s picture

Status: Needs review » Reviewed & tested by the community

Hello, I have just checked patch #18. Things are in order after the reroll. and besides that, it seems to work fine. I'm moving it to RTBC

  • maticb authored d4fb1ba on 8.x-1.x
    Issue #3078811 by guilhermevp, maticb, AndreyMaximov, matthiasm11,...
colan’s picture

Status: Reviewed & tested by the community » Fixed

Thanks all!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.