1 | <?php |
||
7 | abstract class TemplatableField extends Field |
||
8 | { |
||
9 | /** @var string */ |
||
10 | protected $templateKey; |
||
11 | |||
12 | /** @var \Illuminate\Contracts\Translation\Translator */ |
||
13 | protected $translator; |
||
14 | |||
15 | 9 | public function __construct($value, $model, string $templateKey = '') |
|
22 | |||
23 | 9 | protected function parseValue($value): string |
|
24 | { |
||
25 | 9 | $nesting_level = $this->templateKey ?: $this->getNestingLevel(); |
|
26 | |||
27 | 9 | $template_path = $this->getTemplatePath( |
|
28 | 9 | get_class($this->model). |
|
29 | 9 | ($nesting_level ? '.'.$nesting_level : '') |
|
30 | ); |
||
31 | |||
32 | 9 | return $this->translator->has($template_path) ? $this->translator->trans( |
|
33 | 9 | $template_path, |
|
34 | 9 | $this->parseAttributesWithKeys($value) |
|
35 | 9 | ) : $this->model->getAttribute($value); |
|
36 | } |
||
37 | |||
38 | 9 | protected function getTemplatePath(string $templateKey): string |
|
44 | |||
45 | 3 | protected function getNestingLevel(): string |
|
49 | } |
||
50 |