Comment.php
5 months ago
CommentServiceFactory.php
5 months ago
Media.php
5 months ago
MediaServiceFactory.php
5 months ago
Post.php
5 months ago
PostServiceFactory.php
5 months ago
User.php
5 months ago
UserServiceFactory.php
5 months ago
Media.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\TableScreen\ManageValue; |
| 6 | |
| 7 | use AC\Exception\HookTimingException; |
| 8 | use AC\Table\ManageValue\RenderFactory; |
| 9 | use AC\TableScreen\ManageValueService; |
| 10 | use AC\Type\ColumnId; |
| 11 | use AC\Type\Value; |
| 12 | |
| 13 | class Media implements ManageValueService |
| 14 | { |
| 15 | |
| 16 | private RenderFactory $factory; |
| 17 | |
| 18 | private int $priority; |
| 19 | |
| 20 | public function __construct(RenderFactory $factory, int $priority = 100) |
| 21 | { |
| 22 | $this->factory = $factory; |
| 23 | $this->priority = $priority; |
| 24 | } |
| 25 | |
| 26 | public function register(): void |
| 27 | { |
| 28 | if (did_action('manage_media_custom_column')) { |
| 29 | throw HookTimingException::called_too_late('manage_media_custom_column'); |
| 30 | } |
| 31 | |
| 32 | add_action('manage_media_custom_column', [$this, 'render_value'], $this->priority, 2); |
| 33 | } |
| 34 | |
| 35 | public function render_value(...$args): void |
| 36 | { |
| 37 | [$column_id, $row_id] = $args; |
| 38 | |
| 39 | $formatter = $this->factory->create(new ColumnId((string)$column_id)); |
| 40 | |
| 41 | if ($formatter) { |
| 42 | echo $formatter->format(new Value((int)$row_id)); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | } |