<p>After talking with Brad in Craft support we came up with this to put in a plugin. So now when duplicate is called in the admin (list of entries) it is set to disabled. Normal Craft behaviour is to keep the same state as the entry being copied.</p>
<pre><code>//if duplicate sets entry to not live / disabled 
Event::on(
    Entry::class,
    Entry::EVENT_BEFORE_SAVE,
    function(ModelEvent $event) {
        $entry = $event-&gt;sender;

        // If the Entry is being duplicated.
        if ($entry-&gt;duplicateOf) {
            
            $entry-&gt;enabled = false;//set to disabled

        }
});
</code></pre>

CC BY-SA 4.0
2020-11-05T11:06:16.663Z
2020-11-05T18:37:51.073Z
2020-11-05T18:37:51.073Z
Green17
<p>Using <code>duplicateOf</code> is not sufficient to detect duplicates. A draft, provisional draft or revision being applied to the live entry will also have a <code>duplicateOf</code> property, so this will result in live entries being disabled on save (see this <a href="https://github.com/craftcms/cms/issues/10245" rel="nofollow noreferrer">issue on Github</a> for reference).</p>
<p>To be sure the hook only applies to duplicated entries, you also need to check the <a href="https://docs.craftcms.com/api/v3/craft-base-elementtrait.html#updatingfromderivative" rel="nofollow noreferrer"><code>updatingFromDerivative</code> property</a> – if that is false, the entry is being duplicated.</p>
<p>Here's a complete working hook for Craft 3.7:</p>
<pre class="lang-php prettyprint-override"><code>use craft\elements\Entry;
use craft\events\ModelEvent;
use craft\helpers\ElementHelper;

Event::on(
    Entry::class,
    Entry::EVENT_BEFORE_SAVE,
    function (ModelEvent $e) {
        $entry = $e-&gt;sender;
        if (ElementHelper::isDraftOrRevision($entry)) return;
        if (!$entry-&gt;duplicateOf || $entry-&gt;updatingFromDerivative) return;
        $entry-&gt;enabled = false;
    }
);
</code></pre>
<hr />
<p>In Craft 4, duplicated entries will be disabled by default (see the <a href="https://github.com/craftcms/cms/discussions/10244" rel="nofollow noreferrer">discussion on Github</a> for reference).</p>

CC BY-SA 4.0
2021-12-14T10:06:18.393Z
2021-12-16T08:31:55.387Z
2021-12-16T08:31:55.387Z
MoritzLost
<p>Is it possible to duplicate an entry as not enabled/live from the admin listing page? Just this means some user put pages live on the site that are just copies - they forget to quickly change it to disabled etc.</p>
<p><a href="https://i.sstatic.net/tKwyU.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/tKwyU.jpg" alt="enter image description here" /></a></p>

<craft3><admin>
Is it possible to duplicate an entry as not enabled/live from the listing page?
# Is it possible to duplicate an entry as not enabled/live from the listing page?

(Asked by: username_0 on 2020-11-05)

Is it possible to duplicate an entry as not enabled/live from the admin listing page? Just this means some user put pages live on the site that are just copies - they forget to quickly change it to disabled etc.

[![enter image description here](https://i.sstatic.net/tKwyU.jpg)](https://i.sstatic.net/tKwyU.jpg)

**Tags:** craft3, admin


---

## 2 answers

### Answer by username_0 on 2020-11-05. Score: 2

After talking with Brad in Craft support we came up with this to put in a plugin. So now when duplicate is called in the admin (list of entries) it is set to disabled. Normal Craft behaviour is to keep the same state as the entry being copied.
//if duplicate sets entry to not live / disabled 
Event::on(
    Entry::class,
    Entry::EVENT_BEFORE_SAVE,
    function(ModelEvent $event) {
        $entry = $event->sender;

        // If the Entry is being duplicated.
        if ($entry->duplicateOf) {
            
            $entry->enabled = false;//set to disabled

        }
});


---

### Answer by username_1 on 2021-12-14. Score: 1

Using duplicateOf is not sufficient to detect duplicates. A draft, provisional draft or revision being applied to the live entry will also have a duplicateOf property, so this will result in live entries being disabled on save (see this issue on Github for reference).
To be sure the hook only applies to duplicated entries, you also need to check the updatingFromDerivative property – if that is false, the entry is being duplicated.
Here's a complete working hook for Craft 3.7:
use craft\elements\Entry;
use craft\events\ModelEvent;
use craft\helpers\ElementHelper;

Event::on(
    Entry::class,
    Entry::EVENT_BEFORE_SAVE,
    function (ModelEvent $e) {
        $entry = $e->sender;
        if (ElementHelper::isDraftOrRevision($entry)) return;
        if (!$entry->duplicateOf || $entry->updatingFromDerivative) return;
        $entry->enabled = false;
    }
);


In Craft 4, duplicated entries will be disabled by default (see the discussion on Github for reference).


---

