-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: cleanup extend, create serializer mutators (#84)
* chore: cleanup extend, create serializer mutators * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
9acbd74
commit f460073
Showing
5 changed files
with
104 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/polls. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FoF\Polls\Api; | ||
|
||
use Flarum\Api\Serializer\DiscussionSerializer; | ||
use Flarum\Discussion\Discussion; | ||
|
||
class AddDiscussionAttributes | ||
{ | ||
public function __invoke(DiscussionSerializer $serializer, Discussion $discussion, array $attributes): array | ||
{ | ||
$attributes['hasPoll'] = $discussion->polls()->exists(); | ||
$attributes['canStartPoll'] = $serializer->getActor()->can('polls.start', $discussion); | ||
|
||
return $attributes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/polls. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FoF\Polls\Api; | ||
|
||
use Flarum\Api\Serializer\ForumSerializer; | ||
|
||
class AddForumAttributes | ||
{ | ||
public function __invoke(ForumSerializer $serializer, array $model, array $attributes): array | ||
{ | ||
$attributes['canStartPolls'] = $serializer->getActor()->can('discussion.polls.start'); | ||
|
||
return $attributes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/polls. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FoF\Polls\Api; | ||
|
||
class AddPostAttributes | ||
{ | ||
public function __invoke($serializer, $post, $attributes) | ||
{ | ||
$attributes['canStartPoll'] = $serializer->getActor()->can('startPoll', $post); | ||
|
||
return $attributes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/polls. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FoF\Polls\Listeners; | ||
|
||
use Flarum\Settings\Event\Saved; | ||
|
||
class ClearFormatterCache | ||
{ | ||
public function handle(Saved $event): void | ||
{ | ||
foreach ($event->settings as $key => $value) { | ||
if ($key === 'fof-polls.optionsColorBlend') { | ||
resolve('fof-user-bio.formatter')->flush(); | ||
|
||
return; | ||
} | ||
} | ||
} | ||
} |