Skip to content

2.x Update function signatures for ::get_post() and ::get_posts()#2145

Closed
gchtr wants to merge 16 commits into2.x-factoriesfrom
2.x-post-functions
Closed

2.x Update function signatures for ::get_post() and ::get_posts()#2145
gchtr wants to merge 16 commits into2.x-factoriesfrom
2.x-post-functions

Conversation

@gchtr
Copy link
Copy Markdown
Member

@gchtr gchtr commented Jan 6, 2020

Issue

Ticket: #2090, #2094 related to Timber\Post objects.

Solution

Add Helper::doing_it_wrong()

I added a Helper::doing_it_wrong() function, that can be used in combination with a @expectedIncorrectUsage tag in the DocBlock of a test.

This is helpful for functionality that will not be deprecated, but removed, like certain function parameters in Timber::get_post() and Timber::get_posts().

Added in #2196.

Remove query methods that won’t work anymore

The following methods for retrieving post were removed. Yes, removed and not deprecated, because there will be no backwards compatibility.

  • Query strings - Removed the method of getting posts via a query string (like post_type=portfolio) and added a doing-it-wrong message.
  • Getting a post by post slug – Added a doing-it-wrong message to help developers in the transition. Alternatively, we could add a new function Timber::get_post_from_slug() that could do this (Discussion in 2.x Documentation for API #2073).
  • Getting a post by post name – This case is catched with the same doing-it-wrong message as getting a post by post slug (Discussion in 2.x Documentation for API #2073).

Deprecate Timber::query_post() and Timber::query_posts()

The Timber::query_post() and Timber::query_posts() functions weren’t properly deprecated yet.

Return a PostCollection

As per the new API, we always return a PostCollection when using Timber::get_posts(). That’s why I changed the current implementation through PostGetter::get_posts() to use true for the return_collection parameter in Timber::get_posts().

However, a lot of tests still break, because Timber::get_posts() doesn’t return a PostCollection() with the ability to handle pagination yet. I guess we’ll first have to make Timber::get_posts() use the new API before this can be merged. @acobster How would you proceed here?

Impact

This will break backwards compatibility with how Timber::get_post() and Timber::get_posts() worked before. But I added checks and warnings to help developers in the transition.

Usage Changes

See #2073.

Considerations

To keep discussion in one place, I added some remarks and questions in #2073 (comment).

Testing

Yes, but work in progress.

Todo

  • Define default $options for Timber::get_posts()
  • Make Timber::get_posts() return a PostCollection that can handle pagination.
  • Use Iterable as return type for Timber::get_posts(), see 2.x Documentation for API #2073 (comment).

gchtr added 3 commits January 5, 2020 22:41
Use these two functions throughout tests, replace instances of APIs that won’t work in the future.
@gchtr gchtr added 2.0 wip Work in Progress labels Jan 6, 2020
@gchtr
Copy link
Copy Markdown
Member Author

gchtr commented Jan 7, 2020

As per #2073 (comment), I guess I should change this against the 2.x-factories branch.

Copy link
Copy Markdown
Collaborator

@acobster acobster left a comment

Choose a reason for hiding this comment

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

This is looking great at first glance. I'll dig into this further probably tomorrow. Thanks for adding those Helper notices, those look super helpful!

Copy link
Copy Markdown
Collaborator

@acobster acobster left a comment

Choose a reason for hiding this comment

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

Looking great for the most part; please see comments.

@gchtr
Copy link
Copy Markdown
Member Author

gchtr commented Jan 18, 2020

@acobster I guess I should rebase this pull request against 2.x-factories, too?

@gchtr gchtr mentioned this pull request Feb 8, 2020
24 tasks
# Conflicts:
#	lib/Helper.php
#	tests/test-timber-pagination.php
#	tests/test-timber-post-getter.php
@gchtr gchtr requested a review from jarednova as a code owner February 16, 2020 11:00
@gchtr gchtr changed the base branch from 2.x-api to 2.x-factories February 16, 2020 11:01
@gchtr
Copy link
Copy Markdown
Member Author

gchtr commented Jun 10, 2020

@acobster Do you want to merge this into the 2.x-factories branch first and then connect Timber::get_post() and Timber::get_posts() to the Post Factory, or do it here?

@acobster
Copy link
Copy Markdown
Collaborator

acobster commented Jun 10, 2020

@gchtr let's do in 2.x-factories first. Thanks!

@jarednova
Copy link
Copy Markdown
Member

@gchtr are you waiting on me for a review here? I noticed the WIP tag so I had assumed you were still at-work on this.

There are a number of failing tests, mainly related to pagination. Do we need to resolve those here, or is that better done once the merge you and @acobster were discussing is complete?

@acobster
Copy link
Copy Markdown
Collaborator

@jarednova I'm assuming there's going to be a lot of lifting to get these two methods working as we get them over to Factories. That work should probably still be done in 2.x-factories IMHO before we bring it into mainline 2.x.

@acobster
Copy link
Copy Markdown
Collaborator

@gchtr @jarednova I just realized I may have misunderstood the question. I don't really have an opinion about whether these fixes happen in 2.x-post-functions or 2.x-factories, in case that's what you were asking.

Sorry, my brain has been kinda everywhere recently. Maybe you know the feeling. 🙃

@jarednova
Copy link
Copy Markdown
Member

@gchtr the PR has my 👍 on the substance you raise in the original ticket, but I think we should work out (not necessarily solve, but just we're on the same page on this todo you left ...):

Make Timber::get_posts() return a PostCollection that can handle pagination

Right now PostQuerys are essentially this — a subclass of PostCollection that have methods to handle for pagination and the associated data/logic. I think it's crucial that pagination be attached to the returned object as opposed to a separate request.

I'm imagining that most of this code can be brought over into a new class w/o too much hassle; but just wanted to make sure it wasn't lost.

Another thing I encountered when doing some investigation on my local is just the number of jumps from class-to-class a call to Timber::get_posts makes. I'm very much in favor of simplifying this as we adapt to factories even if it means compromising some backwards compatibility in places. The current chain of functions/methods is dizzying (and can't be great for performance either).

You might already be aware or have plans for these. But just wanted to call them out so they don't bite us later!

Copy link
Copy Markdown
Member

@jarednova jarednova left a comment

Choose a reason for hiding this comment

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

Approved with my comment above! I think this probably makes most sense to resolve in the factories branch where the other code updates also live — but I'll let @gchtr and @acobster make that call

@gchtr gchtr mentioned this pull request Aug 17, 2020
@acobster acobster force-pushed the 2.x-factories branch 3 times, most recently from 23c3421 to b0d086a Compare August 17, 2020 22:13
@acobster acobster mentioned this pull request Aug 17, 2020
@gchtr gchtr mentioned this pull request Aug 26, 2020
15 tasks
acobster pushed a commit that referenced this pull request Aug 28, 2020
@acobster
Copy link
Copy Markdown
Collaborator

Ported into #2316 in 3fabc80. Calling this good.

@acobster acobster closed this Sep 27, 2020
@nlemoine nlemoine deleted the 2.x-post-functions branch June 23, 2022 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.0 wip Work in Progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants