1 | <?php |
||
21 | class TableMultilanguageField extends Widget |
||
22 | { |
||
23 | /** |
||
24 | * Field name. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | public $name; |
||
29 | |||
30 | /** |
||
31 | * Field label. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | public $label; |
||
36 | |||
37 | /** |
||
38 | * The model of the current field. |
||
39 | * |
||
40 | * @var ActiveRecord |
||
41 | */ |
||
42 | public $model; |
||
43 | |||
44 | /** |
||
45 | * Model of languages. |
||
46 | * |
||
47 | * @var LanguageFieldInterface |
||
48 | */ |
||
49 | protected $language; |
||
50 | |||
51 | /** |
||
52 | * The value of the empty field is the default. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | public $default = '-'; |
||
57 | |||
58 | /** |
||
59 | * Set the language model. |
||
60 | * |
||
61 | * @param LanguageFieldInterface $language |
||
62 | * |
||
63 | * @return void |
||
64 | */ |
||
65 | public function setLanguage(LanguageFieldInterface $language): void |
||
69 | |||
70 | /** |
||
71 | * Returns the translation of the field. |
||
72 | * |
||
73 | * @throws InvalidConfigException |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function run(): string |
||
93 | |||
94 | /** |
||
95 | * Obtaining a field translation of another model along a given path through a series |
||
96 | * of entities, separated by a point. |
||
97 | * |
||
98 | * @param $name string, separated by dot. |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | private function getDataByPath($name): string |
||
121 | } |
||
122 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: