Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status criteria ignored in EVENT_REGISTER_SOURCES event #4249

Closed
arifje opened this issue May 12, 2019 · 4 comments
Closed

Status criteria ignored in EVENT_REGISTER_SOURCES event #4249

arifje opened this issue May 12, 2019 · 4 comments

Comments

@arifje
Copy link

arifje commented May 12, 2019

So I was trying to create some custom filters in the side menu to filter entries by today/live, today/pending, etc., but the status criteria seems to be ignored completely.

So I tried the example from the docs, but this also doesn't seem to work.

Code;

Event::on(Entry::class, Element::EVENT_REGISTER_SOURCES, function(RegisterElementSourcesEvent $event) {
    if ($event->context === 'index') {
        $event->sources[] = [
            'heading' => \Craft::t('plugin-handle', 'Statuses'),
        ];

        foreach (Entry::statuses() as $status => $label) {
            $event->sources[] = [
                'key' => 'status:'.$status,
                'label' => $label,
                'criteria' => ['status' => $status]
            ];
        }
    }
});

Result: all entries are shown, no matter what status.

Someone on Discord said it may have to do with the fact that the pull down select box is present by default and possibly overriding it. Could be, don't know.

Craft CMS 3.1.26
PHP 7.2
MySQL 5.7

@brandonkelly
Copy link
Member

Yep, the source’s status was being overridden by the status menu in the UI. Next release will start hiding that status menu (and ignoring its value) if the selected source is already defining a status.

@leevigraham
Copy link
Contributor

Tricky one… but should this also be the case for 'status'=>null? In my case I want to always show all statuses.

@brandonkelly
Copy link
Member

@leevigraham I would say no unless we have a way of hiding the status menu for that source as well, otherwise it would be a confusing UI.

@leevigraham
Copy link
Contributor

@leevigraham I would say no unless we have a way of hiding the status menu for that source as well, otherwise it would be a confusing UI.

Fair… I ended up just listing all the statuses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants