2

Just wondering if there's a way to set the default status for the entry listing pages in the admin, in my case from "All" to "Live". This would need to account for a page "refresh" and navigation using the sidebar links.

I've tried to amend the toolbar property available in the passed context for the cp.layouts.base hook but this is purely visual and has no effect on the criteria to query for these entries.

I've attached a screenshot to confirm location for anyone who's unsure. Many thanks in advance!

enter image description here

1
  • 1
    Thanks for this post and the suggested workaround. For anyone that wants to put their support behind a built-in feature for this, here's the feature request on Craft's repo: github.com/craftcms/cms/discussions/8926
    – Matt
    Commented Sep 22, 2021 at 13:37

1 Answer 1

1

After a little head-scratching, the only way I could get this working was to register an AssetBundle (to load in my own JS), and making use of the Garnish toolkit as follows:

$(document).ready(function() {
    var statusSet = false;

    Craft.elementIndex.on('updateElements selectSource', function(data) {
        if (!statusSet) {
            // Find the option (and make sure it actually exists)
            $option = data.target.statusMenu.$options.filter('a[data-status="live"]:first');

            if ($option.length) {
                data.target.setStatus($option.data('status'))
                statusSet = true;
            }
        }
    });
});

This should only trigger the setStatus() process once, even when navigating between sources (which will also be filtered to to the saved status state of "Live"), but allows the user the freedom to change the status again if they so choose.

I hope this helps :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.