Value.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Value\Extended; |
| 6 | |
| 7 | use AC; |
| 8 | use AC\Column; |
| 9 | use AC\Formatter\Aggregate; |
| 10 | use AC\FormatterCollection; |
| 11 | use AC\ListScreen; |
| 12 | use AC\Type; |
| 13 | use AC\Value\ExtendedValueLink; |
| 14 | |
| 15 | class Value implements ExtendedValue |
| 16 | { |
| 17 | public function render( |
| 18 | $id, |
| 19 | array $params, |
| 20 | Column $column, |
| 21 | ListScreen $list_screen |
| 22 | ): string { |
| 23 | $formatters = []; |
| 24 | |
| 25 | foreach ($column->get_formatters() as $formatter) { |
| 26 | if ($formatter instanceof AC\Formatter\ExtendedValueLink) { |
| 27 | continue; |
| 28 | } |
| 29 | |
| 30 | $formatters[] = $formatter; |
| 31 | } |
| 32 | |
| 33 | $formatter = new Aggregate(new FormatterCollection($formatters)); |
| 34 | |
| 35 | return (string)$formatter->format( |
| 36 | new Type\Value($id) |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | public function can_render(string $view): bool |
| 41 | { |
| 42 | return $view === 'value'; |
| 43 | } |
| 44 | |
| 45 | public function get_link($id, string $label): ExtendedValueLink |
| 46 | { |
| 47 | return new ExtendedValueLink($label, $id, 'value'); |
| 48 | } |
| 49 | |
| 50 | } |
| 51 |