@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | if ($object->$group) { |
39 | 39 | $decoded_fields = json_decode($object->$group, true); |
40 | 40 | // In case that some field read the value through $item->$name |
41 | - foreach($decoded_fields as $field_name => $field_value) { |
|
41 | + foreach ($decoded_fields as $field_name => $field_value) { |
|
42 | 42 | $object->setAttribute($field_name, $field_value); |
43 | 43 | } |
44 | 44 | $fields = array_merge($fields, $decoded_fields); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | protected function handleFieldsGroups($fields) { |
52 | 52 | foreach ($this->fieldsGroups as $group => $groupFields) { |
53 | - $fields[$group] = json_encode(Arr::where(Arr::only($fields, $groupFields), function ($value, $key) { |
|
53 | + $fields[$group] = json_encode(Arr::where(Arr::only($fields, $groupFields), function($value, $key) { |
|
54 | 54 | return !empty($value); |
55 | 55 | })); |
56 | 56 | Arr::forget($fields, $groupFields); |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | if (Schema::hasTable(config('twill.related_table', 'related'))) { |
46 | 46 | $relatedItems = Collection::make(); |
47 | 47 | |
48 | - Collection::make($fields['browsers'])->each(function ($items, $browserName) use ($object, &$relatedItems) { |
|
49 | - Collection::make($items)->each(function ($item) use ($browserName, &$relatedItems) { |
|
48 | + Collection::make($fields['browsers'])->each(function($items, $browserName) use ($object, &$relatedItems) { |
|
49 | + Collection::make($items)->each(function($item) use ($browserName, &$relatedItems) { |
|
50 | 50 | try { |
51 | 51 | $repository = $this->getModelRepository($item['endpointType'] ?? $browserName); |
52 | 52 | $relatedItems->push((object) [ |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | public function afterSave($object, $fields) |
74 | 74 | { |
75 | 75 | if (Schema::hasTable(config('twill.related_table', 'related'))) { |
76 | - Collection::make($fields['browsers'])->each(function ($items, $browserName) use ($object) { |
|
76 | + Collection::make($fields['browsers'])->each(function($items, $browserName) use ($object) { |
|
77 | 77 | $object->saveRelated($items, $browserName); |
78 | 78 | }); |
79 | 79 | } |
@@ -100,14 +100,14 @@ discard block |
||
100 | 100 | { |
101 | 101 | $blocksFromConfig = $this->config->get('twill.block_editor.' . ($repeater ? 'repeaters' : 'blocks')); |
102 | 102 | |
103 | - $block['type'] = Collection::make($blocksFromConfig)->search(function ($blockConfig) use ($block) { |
|
103 | + $block['type'] = Collection::make($blocksFromConfig)->search(function($blockConfig) use ($block) { |
|
104 | 104 | return $blockConfig['component'] === $block['type']; |
105 | 105 | }); |
106 | 106 | |
107 | 107 | $block['content'] = empty($block['content']) ? new \stdClass : (object) $block['content']; |
108 | 108 | |
109 | 109 | if ($block['browsers']) { |
110 | - $browsers = Collection::make($block['browsers'])->map(function ($items) { |
|
110 | + $browsers = Collection::make($block['browsers'])->map(function($items) { |
|
111 | 111 | return Collection::make($items)->pluck('id'); |
112 | 112 | })->toArray(); |
113 | 113 |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | |
72 | 72 | $blockRepository->bulkDelete($object->blocks()->pluck('id')->toArray()); |
73 | 73 | |
74 | - $this->getBlocks($object, $fields)->each(function ($block) use ($object, $blockRepository) { |
|
74 | + $this->getBlocks($object, $fields)->each(function($block) use ($object, $blockRepository) { |
|
75 | 75 | |
76 | 76 | $blockCreated = $blockRepository->create($block); |
77 | 77 | |
78 | - $block['blocks']->each(function ($childBlock) use ($blockCreated, $blockRepository) { |
|
78 | + $block['blocks']->each(function($childBlock) use ($blockCreated, $blockRepository) { |
|
79 | 79 | $childBlock['parent_id'] = $blockCreated->id; |
80 | 80 | $blockRepository->create($childBlock); |
81 | 81 | }); |
@@ -174,9 +174,9 @@ discard block |
||
174 | 174 | ]; |
175 | 175 | } |
176 | 176 | |
177 | - $fields['blocksFields'][] = Collection::make($block['content'])->filter(function ($value, $key) { |
|
177 | + $fields['blocksFields'][] = Collection::make($block['content'])->filter(function($value, $key) { |
|
178 | 178 | return $key !== "browsers"; |
179 | - })->map(function ($value, $key) use ($block) { |
|
179 | + })->map(function($value, $key) use ($block) { |
|
180 | 180 | return [ |
181 | 181 | 'name' => "blocks[$block->id][$key]", |
182 | 182 | 'value' => $value, |
@@ -189,15 +189,15 @@ discard block |
||
189 | 189 | |
190 | 190 | if ($medias) { |
191 | 191 | if (config('twill.media_library.translated_form_fields', false)) { |
192 | - $fields['blocksMedias'][] = Collection::make($medias)->mapWithKeys(function ($mediasByLocale, $locale) use ($block) { |
|
193 | - return Collection::make($mediasByLocale)->mapWithKeys(function ($value, $key) use ($block, $locale) { |
|
192 | + $fields['blocksMedias'][] = Collection::make($medias)->mapWithKeys(function($mediasByLocale, $locale) use ($block) { |
|
193 | + return Collection::make($mediasByLocale)->mapWithKeys(function($value, $key) use ($block, $locale) { |
|
194 | 194 | return [ |
195 | 195 | "blocks[$block->id][$key][$locale]" => $value, |
196 | 196 | ]; |
197 | 197 | }); |
198 | 198 | })->filter()->toArray(); |
199 | 199 | } else { |
200 | - $fields['blocksMedias'][] = Collection::make($medias)->mapWithKeys(function ($value, $key) use ($block) { |
|
200 | + $fields['blocksMedias'][] = Collection::make($medias)->mapWithKeys(function($value, $key) use ($block) { |
|
201 | 201 | return [ |
202 | 202 | "blocks[$block->id][$key]" => $value, |
203 | 203 | ]; |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | $files = $blockFormFields['files']; |
209 | 209 | |
210 | 210 | if ($files) { |
211 | - Collection::make($files)->each(function ($rolesWithFiles, $locale) use (&$fields, $block) { |
|
212 | - $fields['blocksFiles'][] = Collection::make($rolesWithFiles)->mapWithKeys(function ($files, $role) use ($locale, $block) { |
|
211 | + Collection::make($files)->each(function($rolesWithFiles, $locale) use (&$fields, $block) { |
|
212 | + $fields['blocksFiles'][] = Collection::make($rolesWithFiles)->mapWithKeys(function($files, $role) use ($locale, $block) { |
|
213 | 213 | return [ |
214 | 214 | "blocks[$block->id][$role][$locale]" => $files, |
215 | 215 | ]; |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | */ |
249 | 249 | protected function getBlockBrowsers($block) |
250 | 250 | { |
251 | - return Collection::make($block['content']['browsers'])->mapWithKeys(function ($ids, $relation) use ($block) { |
|
251 | + return Collection::make($block['content']['browsers'])->mapWithKeys(function($ids, $relation) use ($block) { |
|
252 | 252 | if (Schema::hasTable(config('twill.related_table', 'related')) && $block->getRelated($relation)->isNotEmpty()) { |
253 | - $items = $this->getFormFieldsForRelatedBrowser($block, $relation);; |
|
253 | + $items = $this->getFormFieldsForRelatedBrowser($block, $relation); ; |
|
254 | 254 | } else { |
255 | 255 | $relationRepository = $this->getModelRepository($relation); |
256 | 256 | $relatedItems = $relationRepository->get([], ['id' => $ids], [], -1); |
@@ -260,9 +260,9 @@ discard block |
||
260 | 260 | $sortedRelatedItems[$item->id] = $item; |
261 | 261 | } |
262 | 262 | |
263 | - $items = Collection::make(array_values($sortedRelatedItems))->filter(function ($value) { |
|
263 | + $items = Collection::make(array_values($sortedRelatedItems))->filter(function($value) { |
|
264 | 264 | return is_object($value); |
265 | - })->map(function ($relatedElement) use ($relation) { |
|
265 | + })->map(function($relatedElement) use ($relation) { |
|
266 | 266 | return [ |
267 | 267 | 'id' => $relatedElement->id, |
268 | 268 | 'name' => $relatedElement->titleInBrowser ?? $relatedElement->title, |
@@ -102,7 +102,7 @@ |
||
102 | 102 | 'hasFiles', |
103 | 103 | 'hasPosition', |
104 | 104 | 'hasRevisions', |
105 | - ])->filter(function ($enabled) { |
|
105 | + ])->filter(function($enabled) { |
|
106 | 106 | return $enabled; |
107 | 107 | }); |
108 | 108 |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | |
186 | 186 | foreach ($fields as $field) { |
187 | 187 | if (in_array($field, $translatedAttributes)) { |
188 | - $query->orWhereHas('translations', function ($q) use ($field, $search) { |
|
188 | + $query->orWhereHas('translations', function($q) use ($field, $search) { |
|
189 | 189 | $q->where($field, $this->getLikeOperator(), "%{$search}%"); |
190 | 190 | }); |
191 | 191 | } else { |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | public function create($fields) |
214 | 214 | { |
215 | - return DB::transaction(function () use ($fields) { |
|
215 | + return DB::transaction(function() use ($fields) { |
|
216 | 216 | $original_fields = $fields; |
217 | 217 | |
218 | 218 | $fields = $this->prepareFieldsBeforeCreate($fields); |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function update($id, $fields) |
269 | 269 | { |
270 | - DB::transaction(function () use ($id, $fields) { |
|
270 | + DB::transaction(function() use ($id, $fields) { |
|
271 | 271 | $object = $this->model->findOrFail($id); |
272 | 272 | |
273 | 273 | $this->beforeSave($object, $fields); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | */ |
291 | 291 | public function updateBasic($id, $values, $scopes = []) |
292 | 292 | { |
293 | - return DB::transaction(function () use ($id, $values, $scopes) { |
|
293 | + return DB::transaction(function() use ($id, $values, $scopes) { |
|
294 | 294 | // apply scopes if no id provided |
295 | 295 | if (is_null($id)) { |
296 | 296 | $query = $this->model->query(); |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | |
302 | 302 | $query->update($values); |
303 | 303 | |
304 | - $query->get()->each(function ($object) use ($values) { |
|
304 | + $query->get()->each(function($object) use ($values) { |
|
305 | 305 | $this->afterUpdateBasic($object, $values); |
306 | 306 | }); |
307 | 307 | |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | $query = $this->model->whereIn('id', $id); |
314 | 314 | $query->update($values); |
315 | 315 | |
316 | - $query->get()->each(function ($object) use ($values) { |
|
316 | + $query->get()->each(function($object) use ($values) { |
|
317 | 317 | $this->afterUpdateBasic($object, $values); |
318 | 318 | }); |
319 | 319 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | */ |
337 | 337 | public function setNewOrder($ids) |
338 | 338 | { |
339 | - DB::transaction(function () use ($ids) { |
|
339 | + DB::transaction(function() use ($ids) { |
|
340 | 340 | $this->model->setNewOrder($ids); |
341 | 341 | }, 3); |
342 | 342 | } |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | */ |
348 | 348 | public function delete($id) |
349 | 349 | { |
350 | - return DB::transaction(function () use ($id) { |
|
350 | + return DB::transaction(function() use ($id) { |
|
351 | 351 | if (($object = $this->model->find($id)) === null) { |
352 | 352 | return false; |
353 | 353 | } |
@@ -367,9 +367,9 @@ discard block |
||
367 | 367 | */ |
368 | 368 | public function bulkDelete($ids) |
369 | 369 | { |
370 | - return DB::transaction(function () use ($ids) { |
|
370 | + return DB::transaction(function() use ($ids) { |
|
371 | 371 | try { |
372 | - Collection::make($ids)->each(function ($id) { |
|
372 | + Collection::make($ids)->each(function($id) { |
|
373 | 373 | $this->delete($id); |
374 | 374 | }); |
375 | 375 | } catch (\Exception $e) { |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | */ |
388 | 388 | public function restore($id) |
389 | 389 | { |
390 | - return DB::transaction(function () use ($id) { |
|
390 | + return DB::transaction(function() use ($id) { |
|
391 | 391 | if (($object = $this->model->withTrashed()->find($id)) != null) { |
392 | 392 | $object->restore(); |
393 | 393 | $this->afterRestore($object); |
@@ -404,14 +404,14 @@ discard block |
||
404 | 404 | */ |
405 | 405 | public function bulkRestore($ids) |
406 | 406 | { |
407 | - return DB::transaction(function () use ($ids) { |
|
407 | + return DB::transaction(function() use ($ids) { |
|
408 | 408 | try { |
409 | 409 | $query = $this->model->withTrashed()->whereIn('id', $ids); |
410 | 410 | $objects = $query->get(); |
411 | 411 | |
412 | 412 | $query->restore(); |
413 | 413 | |
414 | - $objects->each(function ($object) { |
|
414 | + $objects->each(function($object) { |
|
415 | 415 | $this->afterRestore($object); |
416 | 416 | }); |
417 | 417 | } catch (\Exception $e) { |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | { |
709 | 709 | if (isset($scopes[$scopeField])) { |
710 | 710 | $id = $scopes[$scopeField]; |
711 | - $query->whereHas($scopeRelation, function ($query) use ($id, $scopeField) { |
|
711 | + $query->whereHas($scopeRelation, function($query) use ($id, $scopeField) { |
|
712 | 712 | $query->where($scopeField, $id); |
713 | 713 | }); |
714 | 714 | unset($scopes[$scopeField]); |
@@ -739,7 +739,7 @@ discard block |
||
739 | 739 | { |
740 | 740 | |
741 | 741 | if (isset($scopes[$scopeField]) && is_string($scopes[$scopeField])) { |
742 | - $query->where(function ($query) use (&$scopes, $scopeField, $orFields) { |
|
742 | + $query->where(function($query) use (&$scopes, $scopeField, $orFields) { |
|
743 | 743 | foreach ($orFields as $field) { |
744 | 744 | $query->orWhere($field, $this->getLikeOperator(), '%' . $scopes[$scopeField] . '%'); |
745 | 745 | unset($scopes[$field]); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function getFormFieldsForBrowser($object, $relation, $routePrefix = null, $titleKey = 'title', $moduleName = null) |
105 | 105 | { |
106 | - return $object->$relation->map(function ($relatedElement) use ($titleKey, $routePrefix, $relation, $moduleName) { |
|
106 | + return $object->$relation->map(function($relatedElement) use ($titleKey, $routePrefix, $relation, $moduleName) { |
|
107 | 107 | return [ |
108 | 108 | 'id' => $relatedElement->id, |
109 | 109 | 'name' => $relatedElement->titleInBrowser ?? $relatedElement->$titleKey, |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function getFormFieldsForRelatedBrowser($object, $relation) |
124 | 124 | { |
125 | - return $object->getRelated($relation)->map(function ($relatedElement) { |
|
125 | + return $object->getRelated($relation)->map(function($relatedElement) { |
|
126 | 126 | return ($relatedElement != null) ? [ |
127 | 127 | 'id' => $relatedElement->id, |
128 | 128 | 'name' => $relatedElement->titleInBrowser ?? $relatedElement->title, |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | ]) + (classHasTrait($relatedElement, HasMedias::class) ? [ |
133 | 133 | 'thumbnail' => $relatedElement->defaultCmsImage(['w' => 100, 'h' => 100]), |
134 | 134 | ] : []) : []; |
135 | - })->reject(function ($item) { |
|
135 | + })->reject(function($item) { |
|
136 | 136 | return empty($item); |
137 | 137 | })->values()->toArray(); |
138 | 138 | } |