Author.php
2 days ago
CommentLink.php
2 days ago
CommentObject.php
2 days ago
CommentText.php
2 days ago
Content.php
2 days ago
LinkableCommentDate.php
2 days ago
Meta.php
2 days ago
MetaDateAndAuthor.php
2 days ago
ParentId.php
2 days ago
Property.php
2 days ago
ReplyToLink.php
2 days ago
StatusLabel.php
2 days ago
UserId.php
2 days 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 | private string $link_to; |
| 14 | |
| 15 | public function __construct(string $link_to) |
| 16 | { |
| 17 | $this->link_to = $link_to; |
| 18 | } |
| 19 | |
| 20 | public function format(Value $value): Value |
| 21 | { |
| 22 | $link = false; |
| 23 | |
| 24 | switch ($this->link_to) { |
| 25 | case 'view_comment': |
| 26 | $link = get_comment_link($value->get_id()); |
| 27 | |
| 28 | break; |
| 29 | case 'edit_comment': |
| 30 | $comment = get_comment($value->get_id()); |
| 31 | |
| 32 | $link = $comment |
| 33 | ? get_edit_comment_link($comment) |
| 34 | : false; |
| 35 | |
| 36 | break; |
| 37 | } |
| 38 | |
| 39 | return $link |
| 40 | ? $value->with_value(Helper\Html::create()->link($link, $value->get_value())) |
| 41 | : $value; |
| 42 | } |
| 43 | |
| 44 | } |
| 45 |