Skip to content

2.x user factories#2160

Merged
acobster merged 32 commits into2.x-factoriesfrom
2.x-user-factories
Jan 17, 2020
Merged

2.x user factories#2160
acobster merged 32 commits into2.x-factoriesfrom
2.x-user-factories

Conversation

@acobster
Copy link
Copy Markdown
Collaborator

@acobster acobster commented Jan 9, 2020

Ticket: #2073 #2088 #2094

Issue

Updating the Users API per discussion in #2073.

Solution

Extensive discussion of the solution is in #2073 and #2093. In short:

  • Timber::get_user and Timber::get_users() no longer take a $UserClass arg; users must now rely on the timber/user/classmap filter to achieve polymorphic instantiation.
  • The public Timber functions use Factories under the hood, which in turn apply timber/user/classmap.

Impact

Discussed in docs.

Usage Changes

Also discussed in the docs.

Considerations

I'm not sure what the new usage of the Twig {{ User(...) }} fn should be. Currently it supports arrays of IDs, which seems a bit astonishing. I'd be in favor or dropping support for this, or at least deprecating that use-case and providing a new {{ Users(...) }} (or {{ UserCollection(...) }}?) function.

Speaking of which, do we need a UserCollection class? I kind of assumed in the back of my mind that we'd want Collections for Users and Terms (we already have CommentThread), but thinking more critically about it, the Loop is the main reason we have PostCollection, and there's not really an analog to that with Users or Terms. I could see there being a use-case for pagination or some other advanced query-related stuff, but I'm not sure. Thoughts?

Edit: oh, and I'm hoping one of you can look at #2157 before we merge this in. :)

Testing

Tests have been refactored and removed where appropriate. The UserFactory class has some prety thorough tests as well. It would be great add to tests for any edge cases y'all can think of.

@acobster acobster requested review from gchtr and jarednova January 9, 2020 03:03
@acobster acobster requested a review from pascalknecht as a code owner January 9, 2020 03:03
@jarednova jarednova added the 2.0 label Jan 9, 2020
@gchtr
Copy link
Copy Markdown
Member

gchtr commented Jan 9, 2020

I'm not sure what the new usage of the Twig {{ User(...) }} fn should be. Currently it supports arrays of IDs, which seems a bit astonishing. I'd be in favor or dropping support for this, or at least deprecating that use-case and providing a new {{ Users(...) }} (or {{ UserCollection(...) }}?) function.

I think this was applied to match the behavior of other other types (post, terms, ...), without thinking about a use case.

But we will deprecate the Twig functions anyway and use the same function names that we use in PHP, see #2144. That would mean we should have a {{ get_users(...) }} function as well. The same goes for the other objects.

Speaking of which, do we need a UserCollection class? I kind of assumed in the back of my mind that we'd want Collections for Users and Terms (we already have CommentThread), but thinking more critically about it, the Loop is the main reason we have PostCollection, and there's not really an analog to that with Users or Terms. I could see there being a use-case for pagination or some other advanced query-related stuff, but I'm not sure. Thoughts?

We discussed this quite some time ago in #1689. My take is that we don’t need UserCollections, because the loop isn’t involved and usually we don’t need pagination. The same goes for Terms. In case we ever need that in the future, we can add it later.

I will have a thorough look at this later this week.

@acobster
Copy link
Copy Markdown
Collaborator Author

acobster commented Jan 9, 2020

@gchtr ok, I remember that discussion now. I guess we can always add a ::get_users() option to return a UserCollection instead of an array if we decide to implement it. It also occurs to me that we should probably have a users.md among the Guides. Do you have the bandwidth to write one up?

@gchtr
Copy link
Copy Markdown
Member

gchtr commented Jan 9, 2020

👍

It also occurs to me that we should probably have a users.md among the Guides . Do you have the bandwidth to write one up?

Yes, I will write one up 👍

Copy link
Copy Markdown
Member

@gchtr gchtr left a comment

Choose a reason for hiding this comment

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

Omg, with factories, the code looks soo clean 🤩.

I added a first couple of comments.

I will come up with a separate pull request for additional inline documentation.

@acobster
Copy link
Copy Markdown
Collaborator Author

@gchtr I just got all unit tests passing for this locally.

Per discussion on #2157 I'm dropping support for Co-Authors Plus for now, as I just don't have time to continue supporting it. Discussion can continue on that PR, where the 2.x-coauthors-fixes branch contains all the code needed to re-add support for it.

How are you feeling about this PR?

@gchtr gchtr mentioned this pull request Jan 12, 2020
Copy link
Copy Markdown
Member

@gchtr gchtr 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 to me!

  • I’m okay with dropping support for Co-Authors Plus and added a note in the Upgrade Guide in ffd474d. As you said, we can always come back later for trying to add support.
  • I added two more tests for the factory in 6995c6f.
  • I added a User Guide in #2167.
  • I added DocBlocks improvements for User Factories in #2168.

@codecov

This comment was marked as outdated.

@jarednova
Copy link
Copy Markdown
Member

jarednova commented Jan 12, 2020

Extensive work here @acobster! I found a few tiny things, but overall this is looking super. Take a look and let me know if you agree with my one substantive change (returning false instead of null when no user found via Timber::get_user_by and other similar methods). This is the pattern I saw in CommentFactory and what would make the most logical sense to me*. Merge if you agree! (or we can discuss what makes the most sense here and close that out)

* I realize there are a few other places in the 2.x codebase not related to factories where things are returning null instead of false. I'll take a separate PR/issue to investigate and resolve these

@jarednova
Copy link
Copy Markdown
Member

... and also to close the loop on CoAuthorsPlus. I think #2157 is the perfect place to either resolve or abandon attempting to make it compatible. Let's not let that block us here

@acobster
Copy link
Copy Markdown
Collaborator Author

@jarednova yeah, I'm assuming the magic Timber getters will still return false when they don't find anything? In keeping with that I think it makes sense to return false here too.

Thanks for adding those tests, looking good 👍

@acobster acobster merged commit 9cf3b05 into 2.x-factories Jan 17, 2020
@acobster acobster deleted the 2.x-user-factories branch January 17, 2020 21:41
@jarednova
Copy link
Copy Markdown
Member

Awesome, feels great to get this merged!

1 similar comment
@jarednova
Copy link
Copy Markdown
Member

Awesome, feels great to get this merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants