Author.php
3 months ago
CommentLink.php
3 months ago
CommentObject.php
3 months ago
CommentText.php
3 months ago
Content.php
3 months ago
LinkableCommentDate.php
3 months ago
Meta.php
3 months ago
MetaDateAndAuthor.php
3 months ago
ParentId.php
3 months ago
Property.php
3 months ago
ReplyToLink.php
3 months ago
StatusLabel.php
3 months ago
UserId.php
3 months ago
CommentLink.php
45 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Formatter\Comment; |
| 6 | |
| 7 | use AC\Formatter; |
| 8 | use AC\Helper; |
| 9 | use AC\Type\Value; |
| 10 | |
| 11 | class CommentLink implements Formatter |
| 12 | { |
| 13 | |
| 14 | private string $link_to; |
| 15 | |
| 16 | public function __construct(string $link_to) |
| 17 | { |
| 18 | $this->link_to = $link_to; |
| 19 | } |
| 20 | |
| 21 | public function format(Value $value): Value |
| 22 | { |
| 23 | $link = false; |
| 24 | |
| 25 | switch ($this->link_to) { |
| 26 | case 'view_comment' : |
| 27 | $link = get_comment_link($value->get_id()); |
| 28 | |
| 29 | break; |
| 30 | case 'edit_comment' : |
| 31 | $comment = get_comment($value->get_id()); |
| 32 | |
| 33 | $link = $comment |
| 34 | ? get_edit_comment_link($comment) |
| 35 | : false; |
| 36 | |
| 37 | break; |
| 38 | } |
| 39 | |
| 40 | return $link |
| 41 | ? $value->with_value(Helper\Html::create()->link($link, $value->get_value())) |
| 42 | : $value; |
| 43 | } |
| 44 | |
| 45 | } |