-
-
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
- Loading branch information
Showing
5 changed files
with
68 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,17 @@ | ||
<?php | ||
|
||
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,15 @@ | ||
<?php | ||
|
||
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,13 @@ | ||
<?php | ||
|
||
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,19 @@ | ||
<?php | ||
|
||
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; | ||
} | ||
} | ||
} | ||
} |