1
0
mirror of https://github.com/flarum/core.git synced 2025-07-28 20:20:34 +02:00

Update for new extension API

This commit is contained in:
Toby Zerner
2015-05-17 10:20:18 +09:30
parent 57bb8702de
commit f8d756d19d

View File

@@ -1,69 +1,60 @@
<?php namespace Flarum\Mentions; <?php namespace Flarum\Mentions;
use Flarum\Support\ServiceProvider; use Flarum\Support\ServiceProvider;
use Illuminate\Contracts\Events\Dispatcher; use Flarum\Extend\EventSubscribers;
use Flarum\Api\Actions\Discussions\ShowAction as DiscussionsShowAction; use Flarum\Extend\ForumAssets;
use Flarum\Api\Actions\Posts\IndexAction as PostsIndexAction; use Flarum\Extend\Relationship;
use Flarum\Api\Actions\Posts\ShowAction as PostsShowAction; use Flarum\Extend\SerializeRelationship;
use Flarum\Api\Actions\Posts\CreateAction as PostsCreateAction; use Flarum\Extend\ApiInclude;
use Flarum\Extend\Formatter;
use Flarum\Extend\NotificationType;
class MentionsServiceProvider extends ServiceProvider class MentionsServiceProvider extends ServiceProvider
{ {
/** public function boot()
* Bootstrap the application events.
*
* @return void
*/
public function boot(Dispatcher $events)
{ {
$events->subscribe('Flarum\Mentions\Handlers\PostMentionsMetadataUpdater'); $this->extend(
$events->subscribe('Flarum\Mentions\Handlers\UserMentionsMetadataUpdater'); new EventSubscribers([
'Flarum\Mentions\Handlers\PostMentionsMetadataUpdater',
'Flarum\Mentions\Handlers\UserMentionsMetadataUpdater'
]),
$this->forumAssets([ new ForumAssets([
__DIR__.'/../js/dist/extension.js', __DIR__.'/../js/dist/extension.js',
__DIR__.'/../less/mentions.less' __DIR__.'/../less/mentions.less'
]); ]),
$this->relationship('Flarum\Core\Models\Post', function ($model) { new Relationship('Flarum\Core\Models\Post', function ($model) {
return $model->belongsToMany('Flarum\Core\Models\Post', 'mentions_posts', 'mentions_id'); return $model->belongsToMany('Flarum\Core\Models\Post', 'mentions_posts', 'mentions_id');
}, 'mentionedBy'); }, 'mentionedBy'),
$this->serializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionedBy', 'Flarum\Api\Serializers\PostBasicSerializer'); new Relationship('Flarum\Core\Models\Post', function ($model) {
return $model->belongsToMany('Flarum\Core\Models\Post', 'mentions_posts', 'post_id', 'mentions_id');
}, 'mentionsPosts'),
DiscussionsShowAction::$include['posts.mentionedBy'] = true; new Relationship('Flarum\Core\Models\Post', function ($model) {
DiscussionsShowAction::$include['posts.mentionedBy.user'] = true; return $model->belongsToMany('Flarum\Core\Models\User', 'mentions_users', 'post_id', 'mentions_id');
}, 'mentionsUsers'),
PostsShowAction::$include['mentionedBy'] = true; new SerializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionedBy', 'Flarum\Api\Serializers\PostBasicSerializer'),
PostsShowAction::$include['mentionedBy.user'] = true;
PostsIndexAction::$include['mentionedBy'] = true; new SerializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionsPosts', 'Flarum\Api\Serializers\PostBasicSerializer'),
PostsIndexAction::$include['mentionedBy.user'] = true;
new SerializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionsUsers', 'Flarum\Api\Serializers\UserBasicSerializer'),
$this->relationship('Flarum\Core\Models\Post', function ($model) { new ApiInclude('discussions.show', ['posts.mentionedBy', 'posts.mentionedBy.user', 'posts.mentionsPosts', 'posts.mentionsPosts.user', 'posts.mentionsUsers'], true),
return $model->belongsToMany('Flarum\Core\Models\Post', 'mentions_posts', 'post_id', 'mentions_id');
}, 'mentionsPosts');
$this->relationship('Flarum\Core\Models\Post', function ($model) { new ApiInclude(['posts.index', 'posts.show'], ['mentionedBy', 'mentionedBy.user'], true),
return $model->belongsToMany('Flarum\Core\Models\User', 'mentions_users', 'post_id', 'mentions_id');
}, 'mentionsUsers');
$this->serializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionsPosts', 'Flarum\Api\Serializers\PostBasicSerializer'); new ApiInclude(['posts.create'], ['mentionsPosts', 'mentionsPosts.mentionedBy'], true),
$this->serializeRelationship('Flarum\Api\Serializers\PostSerializer', 'hasMany', 'mentionsUsers', 'Flarum\Api\Serializers\UserBasicSerializer');
DiscussionsShowAction::$include['posts.mentionsPosts'] = true; new Formatter('postMentions', 'Flarum\Mentions\PostMentionsFormatter'),
DiscussionsShowAction::$include['posts.mentionsPosts.user'] = true;
PostsCreateAction::$include['mentionsPosts'] = true; new Formatter('userMentions', 'Flarum\Mentions\UserMentionsFormatter'),
PostsCreateAction::$include['mentionsPosts.mentionedBy'] = true;
DiscussionsShowAction::$include['posts.mentionsUsers'] = true; (new NotificationType('Flarum\Mentions\PostMentionedNotification'))->enableByDefault('alert'),
(new NotificationType('Flarum\Mentions\UserMentionedNotification'))->enableByDefault('alert')
$this->formatter('postMentions', 'Flarum\Mentions\PostMentionsFormatter'); );
$this->formatter('userMentions', 'Flarum\Mentions\UserMentionsFormatter');
$this->notificationType('Flarum\Mentions\PostMentionedNotification', ['alert' => true]);
$this->notificationType('Flarum\Mentions\UserMentionedNotification', ['alert' => true]);
} }
} }