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

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 :)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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