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

feat: conditional extenders #3759

Merged
merged 2 commits into from
Mar 14, 2023
Merged

feat: conditional extenders #3759

merged 2 commits into from
Mar 14, 2023

Conversation

SychO9
Copy link
Member

@SychO9 SychO9 commented Mar 13, 2023

Changes proposed in this pull request:
Adds support for conditional extenders, needed especially when adding extenders when certain extensions are enabled. (needed for tag mentions).

Here are some usage examples:

return [
    (new Extend\Conditional)
        ->whenExtensionEnabled('flarum-tags', [
                (new Extend\Formatter)
                    ->parse(FormatTagMentions::class)
                    ->unparse(UnparseTagMentions::class),

                (new Extend\ApiController(ListPostsController::class)
                    ->load('mentionsTags'),

                (new Extend\Model(Post::class)
                    ->belongsToMany('mentionsTags', Tag::class, 'post_mentions_tag', 'post_id', 'mentions_tag_id'),

                (new Extend\ApiSerializer(BasicPostSerializer::class))
                    ->hasMany('mentionsTags', TagSerializer::class),
        ]),
]

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).
  • Core developer confirmed locally this works as intended.
  • Tests have been added, or are not appropriate here.

Required changes:

  • Related documentation PR: (Remove if irrelevant)
  • Related core extension PRs: (Remove if irrelevant)

@SychO9 SychO9 requested a review from a team as a code owner March 13, 2023 21:42
@SychO9 SychO9 added this to the 1.8 milestone Mar 14, 2023
Copy link
Member

@imorland imorland left a comment

Choose a reason for hiding this comment

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

I've been considering this for a while now actually. Great job 👍

@SychO9
Copy link
Member Author

SychO9 commented Mar 14, 2023

Inspired by @davwheat & @luceos 🤗

@SychO9 SychO9 merged commit 8372363 into main Mar 14, 2023
@SychO9 SychO9 deleted the sm/conditional-extenders branch March 14, 2023 20:53
Copy link
Member

@luceos luceos left a comment

Choose a reason for hiding this comment

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

Good job. Please do cleanups in different pr's next time, makes reviewing a ton easier 🙈

Comment on lines +23 to +26
/**
* @param ExtenderInterface[] $extenders
*/
public function whenExtensionEnabled(string $extensionId, array $extenders): self
Copy link
Member

Choose a reason for hiding this comment

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

The signature doesn't match the PR comment example. Your example uses a callable as the second argument, not an array. The array is the return response from the callable yes. I assume your example is wrong then..

Also the phpdoc is incorrect, there are two args.

Copy link
Member Author

Choose a reason for hiding this comment

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

yea updated the example thanks

phpdoc doesn't matter, we only add typings for what isn't typed, we can't vanilla type array as ExtenderInterface[], we've being doing this since 1.0 to avoid unnecessary duplication. And the phpdoc standard allows it.

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

Successfully merging this pull request may close these issues.

5 participants