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

Optionally include unpublished entries #7334

Merged

Conversation

arthurperton
Copy link
Contributor

@arthurperton arthurperton commented Jan 10, 2023

This PR applies the policy to exclude unpublished entries by default, and leave the option to include them by using a filter explicitly.

@arthurperton
Copy link
Contributor Author

arthurperton commented Jan 13, 2023

It all seems to work well now.

In StatusQueryBuilder@queriesStatus() you can see that reflection is used to drill down through the decorators and get the protected wheres property from the actual Builder. Again it all works well, but it is also a bit hacky.

It would be nice to access the wheres property by adding a getter to the abstract Builder class. The decorators would automatically forward the call to the Builder and no funky reflection is needed.

@arthurperton
Copy link
Contributor Author

I decided to add the wheres() getter. Ready for review now.

@arthurperton arthurperton marked this pull request as ready for review January 20, 2023 10:00
Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good but I don't think it will work when using the eloquent driver, or any other entry driver.

They won't have a wheres method in it.

It might be tedious but I think we need to override all the where methods.

public function where($column, $operator = null, $value = null, $boolean = 'and')
{
    if ($column === 'status') {
       $this->hasQueriedStatus = true;
    }

    $this->builder->where($column, $operator, $value, $boolean);

    return $this;
}

public function whereIn($column, $values, $boolean = 'and') { ... }
public function orWhereIn($column, $values) { ... }

// etc

@what-the-diff
Copy link

what-the-diff bot commented Feb 2, 2023

  • Fix relationship fieldtype to show unpublished entries
  • Add StatusQueryBuilder for querying status in a more flexible way
  • Use the new query builder on taxonomy terms and entry relationships (entries) fields, so that they can be filtered by any status or published state without breaking existing functionality

@arthurperton
Copy link
Contributor Author

arthurperton commented Feb 2, 2023

Thank you for that feedback. The where.. methods are being intercepted now to check if the status is queried.

@jasonvarga
Copy link
Member

Nice solution.

@arthurperton
Copy link
Contributor Author

arthurperton commented Feb 2, 2023

Thank you. I see now that I actually forgot the basic where method, adding it now.

@stoffelio
Copy link
Contributor

Any chance this will find its way into core with 4.0?

@jasonvarga jasonvarga changed the base branch from 3.3 to 3.4 March 16, 2023 20:50
@jasonvarga
Copy link
Member

Made some small tweaks and adjusted tests.

Also, I added the ability to pass in the $status to the StatusQueryBuilder. We don't actually use it, but I like keeping the class called StatusQueryBuilder. If we left the status hardcoded to published, it's really more of a PublishedQueryBuilder, which just sounds weird. 😂

@jasonvarga jasonvarga merged commit e76740c into statamic:3.4 Mar 17, 2023
@arthurperton
Copy link
Contributor Author

😀 very nice! I am glad that this is integrated.

@aerni aerni mentioned this pull request Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants