@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $relationRepository = $this->getModelRepository($relation, $model); |
| 64 | 64 | |
| 65 | 65 | if (!$keepExisting) { |
| 66 | - $object->$relation()->each(function ($repeaterElement) { |
|
| 66 | + $object->$relation()->each(function($repeaterElement) { |
|
| 67 | 67 | $repeaterElement->forceDelete(); |
| 68 | 68 | }); |
| 69 | 69 | } |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | $morph = $morph ?: $relation; |
| 84 | 84 | |
| 85 | - $morphFieldType = $morph.'_type'; |
|
| 86 | - $morphFieldId = $morph.'_id'; |
|
| 85 | + $morphFieldType = $morph . '_type'; |
|
| 86 | + $morphFieldId = $morph . '_id'; |
|
| 87 | 87 | |
| 88 | 88 | // if no relation field submitted, soft deletes all associated rows |
| 89 | 89 | if (!$relationFields) { |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | if (isset($relatedItemFormFields['medias'])) { |
| 213 | 213 | if (config('twill.media_library.translated_form_fields', false)) { |
| 214 | - Collection::make($relatedItemFormFields['medias'])->each(function ($rolesWithMedias, $locale) use (&$repeatersMedias, $relation, $relationItem) { |
|
| 215 | - $repeatersMedias[] = Collection::make($rolesWithMedias)->mapWithKeys(function ($medias, $role) use ($locale, $relation, $relationItem) { |
|
| 214 | + Collection::make($relatedItemFormFields['medias'])->each(function($rolesWithMedias, $locale) use (&$repeatersMedias, $relation, $relationItem) { |
|
| 215 | + $repeatersMedias[] = Collection::make($rolesWithMedias)->mapWithKeys(function($medias, $role) use ($locale, $relation, $relationItem) { |
|
| 216 | 216 | return [ |
| 217 | 217 | "blocks[$relation-$relationItem->id][$role][$locale]" => $medias, |
| 218 | 218 | ]; |
@@ -226,8 +226,8 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | if (isset($relatedItemFormFields['files'])) { |
| 229 | - Collection::make($relatedItemFormFields['files'])->each(function ($rolesWithFiles, $locale) use (&$repeatersFiles, $relation, $relationItem) { |
|
| 230 | - $repeatersFiles[] = Collection::make($rolesWithFiles)->mapWithKeys(function ($files, $role) use ($locale, $relation, $relationItem) { |
|
| 229 | + Collection::make($relatedItemFormFields['files'])->each(function($rolesWithFiles, $locale) use (&$repeatersFiles, $relation, $relationItem) { |
|
| 230 | + $repeatersFiles[] = Collection::make($rolesWithFiles)->mapWithKeys(function($files, $role) use ($locale, $relation, $relationItem) { |
|
| 231 | 231 | return [ |
| 232 | 232 | "blocks[$relation-$relationItem->id][$role][$locale]" => $files, |
| 233 | 233 | ]; |
@@ -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', 'twill_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, |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | $mediasCollection = Collection::make(); |
| 24 | 24 | $mediasFromFields = $this->getMedias($fields); |
| 25 | 25 | |
| 26 | - $mediasFromFields->each(function ($media) use ($object, $mediasCollection) { |
|
| 26 | + $mediasFromFields->each(function($media) use ($object, $mediasCollection) { |
|
| 27 | 27 | $newMedia = Media::withTrashed()->find(is_array($media['id']) ? Arr::first($media['id']) : $media['id']); |
| 28 | 28 | $pivot = $newMedia->newPivot($object, Arr::except($media, ['id']), config('twill.mediables_table', 'twill_mediables'), true); |
| 29 | 29 | $newMedia->setRelation('pivot', $pivot); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $object->medias()->sync([]); |
| 50 | 50 | |
| 51 | - $this->getMedias($fields)->each(function ($media) use ($object) { |
|
| 51 | + $this->getMedias($fields)->each(function($media) use ($object) { |
|
| 52 | 52 | $object->medias()->attach($media['id'], Arr::except($media, ['id'])); |
| 53 | 53 | }); |
| 54 | 54 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | if (in_array($role, array_keys($this->model->mediasParams ?? [])) |
| 78 | 78 | || in_array($role, array_keys(config('twill.block_editor.crops', []))) |
| 79 | 79 | || in_array($role, array_keys(config('twill.settings.crops', [])))) { |
| 80 | - Collection::make($mediasForRole)->each(function ($media) use (&$medias, $role, $locale) { |
|
| 80 | + Collection::make($mediasForRole)->each(function($media) use (&$medias, $role, $locale) { |
|
| 81 | 81 | $customMetadatas = $media['metadatas']['custom'] ?? []; |
| 82 | 82 | if (isset($media['crops']) && !empty($media['crops'])) { |
| 83 | 83 | foreach ($media['crops'] as $cropName => $cropData) { |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | if (Schema::hasTable(config('twill.related_table', 'twill_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) [ |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | { |
| 75 | 75 | if (Schema::hasTable(config('twill.related_table', 'twill_related'))) { |
| 76 | 76 | if (isset($fields['browsers'])) { |
| 77 | - Collection::make($fields['browsers'])->each(function ($items, $browserName) use ($object) { |
|
| 77 | + Collection::make($fields['browsers'])->each(function($items, $browserName) use ($object) { |
|
| 78 | 78 | $object->saveRelated($items, $browserName); |
| 79 | 79 | }); |
| 80 | 80 | } |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | { |
| 103 | 103 | $blocksFromConfig = $this->config->get('twill.block_editor.' . ($repeater ? 'repeaters' : 'blocks')); |
| 104 | 104 | |
| 105 | - $block['type'] = Collection::make($blocksFromConfig)->search(function ($blockConfig) use ($block) { |
|
| 105 | + $block['type'] = Collection::make($blocksFromConfig)->search(function($blockConfig) use ($block) { |
|
| 106 | 106 | return $blockConfig['component'] === $block['type']; |
| 107 | 107 | }); |
| 108 | 108 | |
| 109 | 109 | $block['content'] = empty($block['content']) ? new \stdClass : (object) $block['content']; |
| 110 | 110 | |
| 111 | 111 | if ($block['browsers']) { |
| 112 | - $browsers = Collection::make($block['browsers'])->map(function ($items) { |
|
| 112 | + $browsers = Collection::make($block['browsers'])->map(function($items) { |
|
| 113 | 113 | return Collection::make($items)->pluck('id'); |
| 114 | 114 | })->toArray(); |
| 115 | 115 | |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | // TODO: document this and actually think about moving to queuable job after content type updates |
| 58 | 58 | public function handle() |
| 59 | 59 | { |
| 60 | - $this->db->table(config('twill.mediables_table', 'twill_mediables'))->orderBy('id')->chunk(100, function ($attached_medias) { |
|
| 60 | + $this->db->table(config('twill.mediables_table', 'twill_mediables'))->orderBy('id')->chunk(100, function($attached_medias) { |
|
| 61 | 61 | foreach ($attached_medias as $attached_media) { |
| 62 | 62 | $uuid = Media::withTrashed()->find($attached_media->media_id, ['uuid'])->uuid; |
| 63 | 63 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | foreach ($fields as $field) { |
| 185 | 185 | if (in_array($field, $translatedAttributes)) { |
| 186 | - $query->orWhereHas('translations', function ($q) use ($field, $search) { |
|
| 186 | + $query->orWhereHas('translations', function($q) use ($field, $search) { |
|
| 187 | 187 | $q->where($field, $this->getLikeOperator(), "%{$search}%"); |
| 188 | 188 | }); |
| 189 | 189 | } else { |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | public function create($fields) |
| 212 | 212 | { |
| 213 | - return DB::transaction(function () use ($fields) { |
|
| 213 | + return DB::transaction(function() use ($fields) { |
|
| 214 | 214 | $original_fields = $fields; |
| 215 | 215 | |
| 216 | 216 | $fields = $this->prepareFieldsBeforeCreate($fields); |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | */ |
| 266 | 266 | public function update($id, $fields) |
| 267 | 267 | { |
| 268 | - DB::transaction(function () use ($id, $fields) { |
|
| 268 | + DB::transaction(function() use ($id, $fields) { |
|
| 269 | 269 | $object = $this->model->findOrFail($id); |
| 270 | 270 | |
| 271 | 271 | $this->beforeSave($object, $fields); |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | */ |
| 289 | 289 | public function updateBasic($id, $values, $scopes = []) |
| 290 | 290 | { |
| 291 | - return DB::transaction(function () use ($id, $values, $scopes) { |
|
| 291 | + return DB::transaction(function() use ($id, $values, $scopes) { |
|
| 292 | 292 | // apply scopes if no id provided |
| 293 | 293 | if (is_null($id)) { |
| 294 | 294 | $query = $this->model->query(); |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | |
| 300 | 300 | $query->update($values); |
| 301 | 301 | |
| 302 | - $query->get()->each(function ($object) use ($values) { |
|
| 302 | + $query->get()->each(function($object) use ($values) { |
|
| 303 | 303 | $this->afterUpdateBasic($object, $values); |
| 304 | 304 | }); |
| 305 | 305 | |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | $query = $this->model->whereIn('id', $id); |
| 312 | 312 | $query->update($values); |
| 313 | 313 | |
| 314 | - $query->get()->each(function ($object) use ($values) { |
|
| 314 | + $query->get()->each(function($object) use ($values) { |
|
| 315 | 315 | $this->afterUpdateBasic($object, $values); |
| 316 | 316 | }); |
| 317 | 317 | |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | */ |
| 335 | 335 | public function setNewOrder($ids) |
| 336 | 336 | { |
| 337 | - DB::transaction(function () use ($ids) { |
|
| 337 | + DB::transaction(function() use ($ids) { |
|
| 338 | 338 | $this->model->setNewOrder($ids); |
| 339 | 339 | }, 3); |
| 340 | 340 | } |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | */ |
| 346 | 346 | public function delete($id) |
| 347 | 347 | { |
| 348 | - return DB::transaction(function () use ($id) { |
|
| 348 | + return DB::transaction(function() use ($id) { |
|
| 349 | 349 | if (($object = $this->model->find($id)) === null) { |
| 350 | 350 | return false; |
| 351 | 351 | } |
@@ -365,9 +365,9 @@ discard block |
||
| 365 | 365 | */ |
| 366 | 366 | public function bulkDelete($ids) |
| 367 | 367 | { |
| 368 | - return DB::transaction(function () use ($ids) { |
|
| 368 | + return DB::transaction(function() use ($ids) { |
|
| 369 | 369 | try { |
| 370 | - Collection::make($ids)->each(function ($id) { |
|
| 370 | + Collection::make($ids)->each(function($id) { |
|
| 371 | 371 | $this->delete($id); |
| 372 | 372 | }); |
| 373 | 373 | } catch (\Exception $e) { |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | public function forceDelete($id) |
| 387 | 387 | { |
| 388 | - return DB::transaction(function () use ($id) { |
|
| 388 | + return DB::transaction(function() use ($id) { |
|
| 389 | 389 | if (($object = $this->model->onlyTrashed()->find($id)) === null) { |
| 390 | 390 | return false; |
| 391 | 391 | } else { |
@@ -402,14 +402,14 @@ discard block |
||
| 402 | 402 | */ |
| 403 | 403 | public function bulkForceDelete($ids) |
| 404 | 404 | { |
| 405 | - return DB::transaction(function () use ($ids) { |
|
| 405 | + return DB::transaction(function() use ($ids) { |
|
| 406 | 406 | try { |
| 407 | 407 | $query = $this->model->onlyTrashed()->whereIn('id', $ids); |
| 408 | 408 | $objects = $query->get(); |
| 409 | 409 | |
| 410 | 410 | $query->forceDelete(); |
| 411 | 411 | |
| 412 | - $objects->each(function ($object) { |
|
| 412 | + $objects->each(function($object) { |
|
| 413 | 413 | $this->afterDelete($object); |
| 414 | 414 | }); |
| 415 | 415 | } catch (\Exception $e) { |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | */ |
| 428 | 428 | public function restore($id) |
| 429 | 429 | { |
| 430 | - return DB::transaction(function () use ($id) { |
|
| 430 | + return DB::transaction(function() use ($id) { |
|
| 431 | 431 | if (($object = $this->model->withTrashed()->find($id)) != null) { |
| 432 | 432 | $object->restore(); |
| 433 | 433 | $this->afterRestore($object); |
@@ -444,14 +444,14 @@ discard block |
||
| 444 | 444 | */ |
| 445 | 445 | public function bulkRestore($ids) |
| 446 | 446 | { |
| 447 | - return DB::transaction(function () use ($ids) { |
|
| 447 | + return DB::transaction(function() use ($ids) { |
|
| 448 | 448 | try { |
| 449 | 449 | $query = $this->model->withTrashed()->whereIn('id', $ids); |
| 450 | 450 | $objects = $query->get(); |
| 451 | 451 | |
| 452 | 452 | $query->restore(); |
| 453 | 453 | |
| 454 | - $objects->each(function ($object) { |
|
| 454 | + $objects->each(function($object) { |
|
| 455 | 455 | $this->afterRestore($object); |
| 456 | 456 | }); |
| 457 | 457 | } catch (\Exception $e) { |
@@ -726,7 +726,7 @@ discard block |
||
| 726 | 726 | { |
| 727 | 727 | if (isset($scopes[$scopeField])) { |
| 728 | 728 | $id = $scopes[$scopeField]; |
| 729 | - $query->whereHas($scopeRelation, function ($query) use ($id, $scopeField) { |
|
| 729 | + $query->whereHas($scopeRelation, function($query) use ($id, $scopeField) { |
|
| 730 | 730 | $query->where($scopeField, $id); |
| 731 | 731 | }); |
| 732 | 732 | unset($scopes[$scopeField]); |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | { |
| 758 | 758 | |
| 759 | 759 | if (isset($scopes[$scopeField]) && is_string($scopes[$scopeField])) { |
| 760 | - $query->where(function ($query) use (&$scopes, $scopeField, $orFields) { |
|
| 760 | + $query->where(function($query) use (&$scopes, $scopeField, $orFields) { |
|
| 761 | 761 | foreach ($orFields as $field) { |
| 762 | 762 | $query->orWhere($field, $this->getLikeOperator(), '%' . $scopes[$scopeField] . '%'); |
| 763 | 763 | unset($scopes[$field]); |
@@ -833,11 +833,11 @@ discard block |
||
| 833 | 833 | |
| 834 | 834 | $uniqueTraits = array_unique(array_map('class_basename', $traits)); |
| 835 | 835 | |
| 836 | - $methods = array_map(function (string $trait) use ($method) { |
|
| 836 | + $methods = array_map(function(string $trait) use ($method) { |
|
| 837 | 837 | return $method . $trait; |
| 838 | 838 | }, $uniqueTraits); |
| 839 | 839 | |
| 840 | - return array_filter($methods, function (string $method) { |
|
| 840 | + return array_filter($methods, function(string $method) { |
|
| 841 | 841 | return method_exists(get_called_class(), $method); |
| 842 | 842 | }); |
| 843 | 843 | } |