@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @var array |
27 | 27 | */ |
28 | - protected $locales = []; |
|
28 | + protected $locales = [ ]; |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @var string |
@@ -36,20 +36,20 @@ discard block |
||
36 | 36 | * Translatable constructor. |
37 | 37 | * @param FieldInterface $field |
38 | 38 | */ |
39 | - public function __construct( FieldInterface $field ) |
|
39 | + public function __construct(FieldInterface $field) |
|
40 | 40 | { |
41 | 41 | /** @var LanguageRepository $languages */ |
42 | - $languages = \App::make( LanguageRepository::class ); |
|
42 | + $languages = \App::make(LanguageRepository::class); |
|
43 | 43 | |
44 | 44 | $this->field = $field; |
45 | 45 | $this->currentLocale = \App::getLocale(); |
46 | 46 | |
47 | - $this->locales = $languages->all()->map( function( Language $language ) |
|
47 | + $this->locales = $languages->all()->map(function(Language $language) |
|
48 | 48 | { |
49 | 49 | return $language->locale; |
50 | 50 | } )->toArray(); |
51 | 51 | |
52 | - parent::__construct( 'translations' ); |
|
52 | + parent::__construct('translations'); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -81,17 +81,17 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function render() |
83 | 83 | { |
84 | - return ( new TranslatableFieldRenderer( $this ) )->render(); |
|
84 | + return (new TranslatableFieldRenderer($this))->render(); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | 88 | * @param $locale |
89 | 89 | * @return FieldSet |
90 | 90 | */ |
91 | - public function getTranslatableResource( $locale ) |
|
91 | + public function getTranslatableResource($locale) |
|
92 | 92 | { |
93 | 93 | return $this->getLocaleFieldSet( |
94 | - $this->getModel()->translateOrNew( $locale ), |
|
94 | + $this->getModel()->translateOrNew($locale), |
|
95 | 95 | $locale |
96 | 96 | ); |
97 | 97 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @param $locale |
102 | 102 | * @return FieldSet |
103 | 103 | */ |
104 | - public function getLocaleFieldSet( $model, $locale ) |
|
104 | + public function getLocaleFieldSet($model, $locale) |
|
105 | 105 | { |
106 | 106 | $fieldSet = new FieldSet( |
107 | 107 | $model, |
@@ -109,17 +109,17 @@ discard block |
||
109 | 109 | ); |
110 | 110 | |
111 | 111 | $field = clone $this->field; |
112 | - $field->setFieldSet( $fieldSet ); |
|
113 | - $field->rules( implode( '|', $this->rules ) ); |
|
112 | + $field->setFieldSet($fieldSet); |
|
113 | + $field->rules(implode('|', $this->rules)); |
|
114 | 114 | |
115 | - $defaultResource = $this->getDefaultResourceForLocale( $locale ); |
|
115 | + $defaultResource = $this->getDefaultResourceForLocale($locale); |
|
116 | 116 | |
117 | - if( $defaultResource && !$field->getValue() ) |
|
117 | + if ($defaultResource && !$field->getValue()) |
|
118 | 118 | { |
119 | - $field->setValue( $defaultResource->{$field->getName()} ); |
|
119 | + $field->setValue($defaultResource->{$field->getName()} ); |
|
120 | 120 | } |
121 | 121 | |
122 | - $fieldSet->push( $field ); |
|
122 | + $fieldSet->push($field); |
|
123 | 123 | |
124 | 124 | return $fieldSet; |
125 | 125 | } |
@@ -130,15 +130,15 @@ discard block |
||
130 | 130 | * @param $locale |
131 | 131 | * @return Model|null |
132 | 132 | */ |
133 | - public function getDefaultResourceForLocale( $locale ) |
|
133 | + public function getDefaultResourceForLocale($locale) |
|
134 | 134 | { |
135 | 135 | $resource = null; |
136 | 136 | |
137 | - if( $this->getValue() && !$this->getValue()->isEmpty() ) |
|
137 | + if ($this->getValue() && !$this->getValue()->isEmpty()) |
|
138 | 138 | { |
139 | - foreach( $this->getValue() as $index => $item ) |
|
139 | + foreach ($this->getValue() as $index => $item) |
|
140 | 140 | { |
141 | - if( $item->{$this->getModel()->getLocaleKey()} === $locale ) |
|
141 | + if ($item->{$this->getModel()->getLocaleKey()} === $locale) |
|
142 | 142 | { |
143 | 143 | $resource = $item; |
144 | 144 | } |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | /** |
152 | 152 | * @param Request $request |
153 | 153 | */ |
154 | - public function beforeModelSave( Request $request ) |
|
154 | + public function beforeModelSave(Request $request) |
|
155 | 155 | { |
156 | - foreach( $this->locales as $locale ) |
|
156 | + foreach ($this->locales as $locale) |
|
157 | 157 | { |
158 | - foreach( $this->getTranslatableResource( $locale )->getFields() as $field ) |
|
158 | + foreach ($this->getTranslatableResource($locale)->getFields() as $field) |
|
159 | 159 | { |
160 | - $field->beforeModelSave( $request ); |
|
160 | + $field->beforeModelSave($request); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
@@ -165,13 +165,13 @@ discard block |
||
165 | 165 | /** |
166 | 166 | * @param Request $request |
167 | 167 | */ |
168 | - public function afterModelSave( Request $request ) |
|
168 | + public function afterModelSave(Request $request) |
|
169 | 169 | { |
170 | - foreach( $this->locales as $locale ) |
|
170 | + foreach ($this->locales as $locale) |
|
171 | 171 | { |
172 | - foreach( $this->getTranslatableResource( $locale )->getFields() as $field ) |
|
172 | + foreach ($this->getTranslatableResource($locale)->getFields() as $field) |
|
173 | 173 | { |
174 | - $field->afterModelSave( $request ); |
|
174 | + $field->afterModelSave($request); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | } |
@@ -181,13 +181,13 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function getRules(): array |
183 | 183 | { |
184 | - $rules = []; |
|
184 | + $rules = [ ]; |
|
185 | 185 | |
186 | 186 | $translationsClass = $this->getModel()->getTranslationModelName(); |
187 | 187 | |
188 | - foreach( $this->getLocaleFieldSet( new $translationsClass, '*' )->getFields() as $field ) |
|
188 | + foreach ($this->getLocaleFieldSet(new $translationsClass, '*')->getFields() as $field) |
|
189 | 189 | { |
190 | - $rules = array_merge( $rules, $field->getRules() ); |
|
190 | + $rules = array_merge($rules, $field->getRules()); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | return $rules; |