TransWikia.com

Is it possible to duplicate an entry as not enabled/live from the listing page?

Craft CMS Asked on January 21, 2021

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

One Answer

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

        }
});

Answered by Green17 on January 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP