@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | // Mark the slug as deleted to avoid any conflict with newly created modules with the same slug. |
36 | 36 | if ($model instanceof Module) { |
37 | 37 | $model->update([ |
38 | - 'slug' => $model->slug . $this->deletionAppendix(), |
|
38 | + 'slug' => $model->slug.$this->deletionAppendix(), |
|
39 | 39 | ]); |
40 | 40 | } |
41 | 41 | |
@@ -70,6 +70,6 @@ discard block |
||
70 | 70 | |
71 | 71 | private function deletionAppendix(): string |
72 | 72 | { |
73 | - return '_DELETED_' . time(); |
|
73 | + return '_DELETED_'.time(); |
|
74 | 74 | } |
75 | 75 | } |
@@ -27,12 +27,12 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function saveFields(Fields $fields, array $input, array $files): void |
29 | 29 | { |
30 | - foreach($fields as $field){ |
|
31 | - if($this->detectCustomSaveMethod($field)) { |
|
30 | + foreach ($fields as $field) { |
|
31 | + if ($this->detectCustomSaveMethod($field)) { |
|
32 | 32 | continue; |
33 | 33 | } |
34 | 34 | |
35 | - if(!$field->isLocalized()) |
|
35 | + if (!$field->isLocalized()) |
|
36 | 36 | { |
37 | 37 | // Set standard non-localized attribute on the model |
38 | 38 | ($customSetMethod = $this->detectCustomSetMethod($field)) |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | // Dynamic localized values or standard translated |
46 | 46 | // For standard translations we set value with the colon notation, e.g. title:en |
47 | 47 | $this->foreachTranslationEntry(data_get($input, 'trans', []), function($locale, $key, $value) use($field){ |
48 | - if($key !== $field->getColumn()) return; |
|
48 | + if ($key !== $field->getColumn()) return; |
|
49 | 49 | |
50 | - if($this->isFieldForDynamicValue($field)) { |
|
50 | + if ($this->isFieldForDynamicValue($field)) { |
|
51 | 51 | $this->setDynamic($key, $value, $locale); |
52 | - } else { |
|
52 | + }else { |
|
53 | 53 | $this->{$field->getColumn().':'.$locale} = $value; |
54 | 54 | } |
55 | 55 | }); |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | $this->save(); |
59 | 59 | |
60 | 60 | // Custom save methods |
61 | - foreach($fields as $field){ |
|
62 | - if($customSaveMethod = $this->detectCustomSaveMethod($field)) { |
|
61 | + foreach ($fields as $field) { |
|
62 | + if ($customSaveMethod = $this->detectCustomSaveMethod($field)) { |
|
63 | 63 | $this->$customSaveMethod($field, $input, $files); |
64 | 64 | } |
65 | 65 | } |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | |
73 | 73 | private function detectCustomSaveMethod(Field $field): ?string |
74 | 74 | { |
75 | - $saveMethodByKey = 'save' . ucfirst(Str::camel($field->getKey())) . 'Field'; |
|
76 | - $saveMethodByType = 'save' . ucfirst(Str::camel($field->getType()->get())) . 'Fields'; |
|
75 | + $saveMethodByKey = 'save'.ucfirst(Str::camel($field->getKey())).'Field'; |
|
76 | + $saveMethodByType = 'save'.ucfirst(Str::camel($field->getType()->get())).'Fields'; |
|
77 | 77 | |
78 | 78 | foreach ([$saveMethodByKey, $saveMethodByType] as $saveMethod) { |
79 | 79 | if (method_exists($this, $saveMethod)) { |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | private function detectCustomSetMethod(Field $field): ?string |
88 | 88 | { |
89 | - $methodName = 'set' . ucfirst(Str::camel($field->getKey())) . 'Field'; |
|
89 | + $methodName = 'set'.ucfirst(Str::camel($field->getKey())).'Field'; |
|
90 | 90 | |
91 | 91 | return (method_exists($this, $methodName)) ? $methodName : null; |
92 | 92 | } |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | |
109 | 109 | private function saveImageFields(ImageField $field, array $input) |
110 | 110 | { |
111 | - app(ImageFieldHandler::class)->handle($this, $field, data_get($input, 'images.' . $field->getName(), []), $input); |
|
111 | + app(ImageFieldHandler::class)->handle($this, $field, data_get($input, 'images.'.$field->getName(), []), $input); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | private function foreachTranslationEntry(array $translations, \Closure $callback) |
115 | 115 | { |
116 | - foreach($translations as $locale => $trans){ |
|
117 | - foreach($trans as $key => $value){ |
|
116 | + foreach ($translations as $locale => $trans) { |
|
117 | + foreach ($trans as $key => $value) { |
|
118 | 118 | call_user_func($callback, $locale, $key, $value); |
119 | 119 | } |
120 | 120 | } |
@@ -45,7 +45,9 @@ |
||
45 | 45 | // Dynamic localized values or standard translated |
46 | 46 | // For standard translations we set value with the colon notation, e.g. title:en |
47 | 47 | $this->foreachTranslationEntry(data_get($input, 'trans', []), function($locale, $key, $value) use($field){ |
48 | - if($key !== $field->getColumn()) return; |
|
48 | + if($key !== $field->getColumn()) { |
|
49 | + return; |
|
50 | + } |
|
49 | 51 | |
50 | 52 | if($this->isFieldForDynamicValue($field)) { |
51 | 53 | $this->setDynamic($key, $value, $locale); |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | |
22 | 22 | public function find(string $modelClass): Manager |
23 | 23 | { |
24 | - if(!isset($this->map[$modelClass])) { |
|
25 | - throw new \InvalidArgumentException('No manager mapped to model ' . $modelClass .'. Make sure to register the manager.'); |
|
24 | + if (!isset($this->map[$modelClass])) { |
|
25 | + throw new \InvalidArgumentException('No manager mapped to model '.$modelClass.'. Make sure to register the manager.'); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | return app($this->map[$modelClass]); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | public function all(): array |
32 | 32 | { |
33 | - return array_map(function($managerClass){ |
|
33 | + return array_map(function($managerClass) { |
|
34 | 34 | return app($managerClass); |
35 | 35 | }, $this->map); |
36 | 36 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | |
29 | 29 | protected function viewData(): array |
30 | 30 | { |
31 | - return array_merge( parent::viewData(),[ |
|
31 | + return array_merge(parent::viewData(), [ |
|
32 | 32 | 'options' => $this->options, |
33 | 33 | ]); |
34 | 34 | } |
@@ -107,7 +107,9 @@ |
||
107 | 107 | // Astrotomic translatable |
108 | 108 | if($model instanceof Translatable) { |
109 | 109 | foreach (config('thinktomorrow.chief.locales') as $locale) { |
110 | - if(!isset($trans[$locale])) $trans[$locale] = []; |
|
110 | + if(!isset($trans[$locale])) { |
|
111 | + $trans[$locale] = []; |
|
112 | + } |
|
111 | 113 | |
112 | 114 | $trans[$locale] = array_merge($trans[$locale], $model->getTranslation($locale)->toArray()); |
113 | 115 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace Thinktomorrow\Chief\PageBuilder; |
6 | 6 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $availableChildren = AvailableChildren::forParent($model); |
42 | 42 | |
43 | 43 | // Only include modules of this model or shared ones. |
44 | - $modules = $availableChildren->onlyModules()->reject(function ($module) use ($model) { |
|
44 | + $modules = $availableChildren->onlyModules()->reject(function($module) use ($model) { |
|
45 | 45 | return $module->owner_id != null && $module->owner_id != $model->id; |
46 | 46 | }); |
47 | 47 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $available_sets = ModelReferencePresenter::toGroupedSelectValues($availableChildren->onlySets())->toArray(); |
51 | 51 | |
52 | 52 | // Current sections |
53 | - $sections = $model->children()->map(function ($section, $index) use($model) { |
|
53 | + $sections = $model->children()->map(function($section, $index) use($model) { |
|
54 | 54 | // if ($section instanceof TranslatableContract) { |
55 | 55 | // |
56 | 56 | // } |
@@ -87,14 +87,14 @@ discard block |
||
87 | 87 | $trans = []; |
88 | 88 | |
89 | 89 | // Has dynamic attributes |
90 | - if(public_method_exists($model, 'dynamic')) { |
|
90 | + if (public_method_exists($model, 'dynamic')) { |
|
91 | 91 | foreach (config('thinktomorrow.chief.locales') as $locale) { |
92 | 92 | $trans[$locale] = []; |
93 | 93 | |
94 | - foreach($model->rawDynamicValues() as $key => $values) { |
|
95 | - if(is_array($values)) { |
|
96 | - foreach($values as $dynamicLocale => $dynamicValue) { |
|
97 | - if($dynamicLocale === $locale) { |
|
94 | + foreach ($model->rawDynamicValues() as $key => $values) { |
|
95 | + if (is_array($values)) { |
|
96 | + foreach ($values as $dynamicLocale => $dynamicValue) { |
|
97 | + if ($dynamicLocale === $locale) { |
|
98 | 98 | $trans[$locale][$key] = $dynamicValue; |
99 | 99 | } |
100 | 100 | } |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | // Astrotomic translatable |
107 | - if($model instanceof Translatable) { |
|
107 | + if ($model instanceof Translatable) { |
|
108 | 108 | foreach (config('thinktomorrow.chief.locales') as $locale) { |
109 | - if(!isset($trans[$locale])) $trans[$locale] = []; |
|
109 | + if (!isset($trans[$locale])) $trans[$locale] = []; |
|
110 | 110 | |
111 | 111 | $trans[$locale] = array_merge($trans[$locale], $model->getTranslation($locale)->toArray()); |
112 | 112 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | ->orderBy('sort', 'ASC') |
55 | 55 | ->get(); |
56 | 56 | |
57 | - return $relations->map(function (Relation $relation) { |
|
57 | + return $relations->map(function(Relation $relation) { |
|
58 | 58 | $parent = $relation->parent; |
59 | 59 | $parent->relation = $relation; |
60 | 60 | |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | ->orderBy('sort', 'ASC') |
71 | 71 | ->get(); |
72 | 72 | |
73 | - return $relations->map(function (Relation $relation) use ($parent_type, $parent_id) { |
|
73 | + return $relations->map(function(Relation $relation) use ($parent_type, $parent_id) { |
|
74 | 74 | |
75 | 75 | // It could be that the child itself is soft-deleted, if this is the case, we will ignore it and move on. |
76 | 76 | if (!$child = $relation->child) { |
77 | 77 | if (!$relation->child()->withTrashed()->first()) { |
78 | 78 | // If we cannot retrieve it then the relation type is possibly wrong, this is a database inconsistency and should be addressed |
79 | - throw new \DomainException('Corrupt relation reference. Related child [' . $relation->child_type . '@' . $relation->child_id . '] could not be retrieved for parent [' . $parent_type . '@' . $parent_id . ']. Make sure the morph key can resolve to a valid class.'); |
|
79 | + throw new \DomainException('Corrupt relation reference. Related child ['.$relation->child_type.'@'.$relation->child_id.'] could not be retrieved for parent ['.$parent_type.'@'.$parent_id.']. Make sure the morph key can resolve to a valid class.'); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | return null; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | }) |
89 | 89 | |
90 | 90 | // In case of soft-deleted entries, this will be null and should be ignored. We make sure that keys are reset in case of removed child |
91 | - ->reject(function ($child) { |
|
91 | + ->reject(function($child) { |
|
92 | 92 | return is_null($child); |
93 | 93 | }) |
94 | 94 | ->values(); |
@@ -105,10 +105,10 @@ discard block |
||
105 | 105 | |
106 | 106 | public static function deleteRelationsOf($type, $id) |
107 | 107 | { |
108 | - $relations = static::where(function ($query) use ($type, $id) { |
|
108 | + $relations = static::where(function($query) use ($type, $id) { |
|
109 | 109 | return $query->where('parent_type', $type) |
110 | 110 | ->where('parent_id', $id); |
111 | - })->orWhere(function ($query) use ($type, $id) { |
|
111 | + })->orWhere(function($query) use ($type, $id) { |
|
112 | 112 | return $query->where('child_type', $type) |
113 | 113 | ->where('child_id', $id); |
114 | 114 | })->get(); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | |
121 | 121 | public static function deleteAllChildRelationsOf($type, $id) |
122 | 122 | { |
123 | - $relations = static::where(function ($query) use ($type, $id) { |
|
123 | + $relations = static::where(function($query) use ($type, $id) { |
|
124 | 124 | return $query->where('parent_type', $type) |
125 | 125 | ->where('parent_id', $id); |
126 | 126 | })->get(); |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | public static function deleteAllParentRelationsOf($type, $id) |
134 | 134 | { |
135 | - $relations = static::where(function ($query) use ($type, $id) { |
|
135 | + $relations = static::where(function($query) use ($type, $id) { |
|
136 | 136 | return $query->where('child_type', $type) |
137 | 137 | ->where('child_id', $id); |
138 | 138 | })->get(); |
@@ -21,13 +21,13 @@ discard block |
||
21 | 21 | $assets = Asset::with('media')->orderBy('created_at', 'DESC')->select('assets.*'); |
22 | 22 | |
23 | 23 | if ($search) { |
24 | - $assets->whereHas('media', function (Builder $query) use ($search) { |
|
25 | - $query->where('file_name', 'LIKE', '%' . $search . '%'); |
|
24 | + $assets->whereHas('media', function(Builder $query) use ($search) { |
|
25 | + $query->where('file_name', 'LIKE', '%'.$search.'%'); |
|
26 | 26 | }); |
27 | 27 | } |
28 | 28 | |
29 | 29 | if ($unused) { |
30 | - $assets->whereNotExists(function ($query) { |
|
30 | + $assets->whereNotExists(function($query) { |
|
31 | 31 | $query->select(DB::raw(1)) |
32 | 32 | ->from('asset_pivots') |
33 | 33 | ->whereRaw('asset_pivots.asset_id = assets.id') |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | }); |
36 | 36 | } |
37 | 37 | |
38 | - if($owner){ |
|
38 | + if ($owner) { |
|
39 | 39 | $owner = ModelReference::fromString($owner)->instance(); |
40 | 40 | $modelAssets = collect(); |
41 | 41 | $modelAssets = $modelAssets->merge($owner->assets()); |
@@ -54,7 +54,7 @@ |
||
54 | 54 | { |
55 | 55 | foreach ($modelReferences as $locale => $modelReferenceString) { |
56 | 56 | if (!$modelReferenceString) { |
57 | - throw new \InvalidArgumentException('Homepage setting value cannot be empty. Value for locale ' . $locale . ' is missing.'); |
|
57 | + throw new \InvalidArgumentException('Homepage setting value cannot be empty. Value for locale '.$locale.' is missing.'); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | { |
11 | 11 | public static function toSelectValues(Collection $collection): Collection |
12 | 12 | { |
13 | - return $collection->map(function (ProvidesModelReference $item) { |
|
13 | + return $collection->map(function(ProvidesModelReference $item) { |
|
14 | 14 | return [ |
15 | 15 | 'id' => $item->modelReference()->get(), |
16 | 16 | 'label' => $item->modelReferenceLabel(), |
@@ -23,10 +23,10 @@ discard block |
||
23 | 23 | { |
24 | 24 | $grouped = []; |
25 | 25 | |
26 | - static::toSelectValues($collection)->each(function ($item) use (&$grouped) { |
|
26 | + static::toSelectValues($collection)->each(function($item) use (&$grouped) { |
|
27 | 27 | if (isset($grouped[$item['group']])) { |
28 | 28 | $grouped[$item['group']]['values'][] = $item; |
29 | - } else { |
|
29 | + }else { |
|
30 | 30 | $grouped[$item['group']] = ['group' => $item['group'], 'values' => [$item]]; |
31 | 31 | } |
32 | 32 | }); |