How to Customize a Source in Element Index to default to "Drafts" Status #19034
-
|
We have a workflow where a Draft entry is created, reviewed, and published. Different people are responsible for different steps in the process and right now the folks reviewing Drafts have to go to the Source, manually select "Drafts" from the statuses to see all the drafts. I'd love to create a second Source and just have it default to the Drafts status view so folks reviewing Drafts could just use that. Right now, they can do this if they bookmark the URL but that's yet another separate workflow that needs to be communicated and managed outside of the CMS UI. I've tried leaning on Entry::EVENT_REGISTER_SOURCES to customize the query, injecting js via View::EVENT_BEFORE_RENDER_TEMPLATE to just manually add &status=drafts to the URL, and adding a custom behavior to the Entry Element to override the Entry::statuses() method. None of those paths have lead to anything useful. Is there any way to have a custom source default to a specific status? If not, is this a worthwhile FR? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Unpublished drafts are included in the “All” status as well — so long as they have been edited whatsoever beyond their initial new entry state.
To only show unpublished drafts, you need to include Event::on(Entry::class, Entry::EVENT_REGISTER_SOURCES, function (RegisterElementSourcesEvent $event) {
$event->sources[] = [
'key' => 'unpublished-drafts',
'label' => 'Unpublished Drafts,
'criteria' => [
'drafts' => true,
'draftOf' => false,
],
];
}); |
Beta Was this translation helpful? Give feedback.
-
|
I might still be missing something but this example is not working for me. On Craft 5.9.20. Using the following event in a custom module: When I implement this and select the "Drafts View" source I no results in the listing (I have drafts in the section I'm testing) and I see the status bar set to "All" by default. If I select "Live" I see all the entries in my section in the results. And if I select "Drafts" I see the expected Drafts in the results. Requiring the same extra steps for the user in the default channel listing. If I add With the forced |
Beta Was this translation helpful? Give feedback.

Unpublished drafts are included in the “All” status as well — so long as they have been edited whatsoever beyond their initial new entry state.
To only show unpublished drafts, you need to include
'draftOf' => falsein the criteria: