@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function getByOwner(FragmentsOwner $owner): Collection |
28 | 28 | { |
29 | - if(!$context = ContextModel::ownedBy($owner)) return collect(); |
|
29 | + if (!$context = ContextModel::ownedBy($owner)) return collect(); |
|
30 | 30 | |
31 | 31 | $fragmentModels = $context->fragments()->get(); |
32 | 32 | |
@@ -44,16 +44,16 @@ discard block |
||
44 | 44 | |
45 | 45 | private function prefetchRecords(Collection $fragmentModels) |
46 | 46 | { |
47 | - $fragmentModels->mapToGroups(function(FragmentModel $fragmentModel){ |
|
47 | + $fragmentModels->mapToGroups(function(FragmentModel $fragmentModel) { |
|
48 | 48 | return [ModelReference::fromString($fragmentModel->model_reference)->className() => ModelReference::fromString($fragmentModel->model_reference)->id()]; |
49 | - })->reject(function($modelIds, $className){ |
|
49 | + })->reject(function($modelIds, $className) { |
|
50 | 50 | $reflection = new ReflectionClass($className); |
51 | 51 | return !$reflection->isSubclassOf(Model::class); |
52 | - })->each(function($modelIds, $className){ |
|
52 | + })->each(function($modelIds, $className) { |
|
53 | 53 | $modelIds = $modelIds->filter(fn($modelId) => $modelId !== 0); |
54 | 54 | $records = $className::withoutGlobalScopes()->whereIn('id', $modelIds->toArray())->get(); |
55 | 55 | |
56 | - $records->each(function($record){ |
|
56 | + $records->each(function($record) { |
|
57 | 57 | $this->prefetchedRecords[$record->modelReference()->get()] = $record; |
58 | 58 | }); |
59 | 59 | }); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | private function fragmentFactory(FragmentModel $fragmentModel): Fragmentable |
63 | 63 | { |
64 | 64 | return $this->prefetchedRecords |
65 | - ->get($fragmentModel->model_reference, fn() => ModelReference::fromString($fragmentModel->model_reference)->instance()) |
|
65 | + ->get($fragmentModel->model_reference, fn() => ModelReference::fromString($fragmentModel->model_reference)->instance()) |
|
66 | 66 | ->setFragmentModel($fragmentModel); |
67 | 67 | } |
68 | 68 |
@@ -26,7 +26,9 @@ |
||
26 | 26 | */ |
27 | 27 | public function getByOwner(FragmentsOwner $owner): Collection |
28 | 28 | { |
29 | - if(!$context = ContextModel::ownedBy($owner)) return collect(); |
|
29 | + if(!$context = ContextModel::ownedBy($owner)) { |
|
30 | + return collect(); |
|
31 | + } |
|
30 | 32 | |
31 | 33 | $fragmentModels = $context->fragments()->get(); |
32 | 34 |
@@ -14,8 +14,8 @@ |
||
14 | 14 | public static function ownedBy(FragmentsOwner $owner): ?ContextModel |
15 | 15 | { |
16 | 16 | return static::where('owner_type', $owner->modelReference()->className()) |
17 | - ->where('owner_id', $owner->modelReference()->id()) |
|
18 | - ->first(); |
|
17 | + ->where('owner_id', $owner->modelReference()->id()) |
|
18 | + ->first(); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function createForOwner(FragmentsOwner $owner): ContextModel |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | public function renderFragment($owner, $loop, $fragments, $viewData): string |
23 | 23 | { |
24 | 24 | // Default (legacy) view rendering |
25 | - if(public_method_exists($this, 'renderView')) { |
|
25 | + if (public_method_exists($this, 'renderView')) { |
|
26 | 26 | return $this->renderView(); |
27 | 27 | } |
28 | 28 | |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | public function fragmentModel(): FragmentModel |
40 | 40 | { |
41 | - if(!isset($this->fragmentModel)) { |
|
41 | + if (!isset($this->fragmentModel)) { |
|
42 | 42 | throw new \DomainException('FragmentModel property on ['.get_class($this).'] expected to be set, but it\'s not.'); |
43 | 43 | } |
44 | 44 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $targetModel = Morphables::instance($targetUrlRecord->model_type)->find($targetUrlRecord->model_id); |
36 | 36 | |
37 | 37 | if (!$targetModel) { |
38 | - throw new ArchivedUrlException('Corrupt target model for this url request. Model by reference [' . $targetUrlRecord->model_type . '@' . $targetUrlRecord->model_id . '] has probably been archived or deleted.'); |
|
38 | + throw new ArchivedUrlException('Corrupt target model for this url request. Model by reference ['.$targetUrlRecord->model_type.'@'.$targetUrlRecord->model_id.'] has probably been archived or deleted.'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return static::createRedirect($targetModel->url($locale)); |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | if (!$model) { |
48 | - throw new ArchivedUrlException('Corrupt target model for this url request. Model by reference [' . $urlRecord->model_type . '@' . $urlRecord->model_id . '] has probably been archived or deleted.'); |
|
48 | + throw new ArchivedUrlException('Corrupt target model for this url request. Model by reference ['.$urlRecord->model_type.'@'.$urlRecord->model_id.'] has probably been archived or deleted.'); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | if (public_method_exists($model, 'isPublished') && !$model->isPublished()) { |
52 | 52 | |
53 | 53 | /** When admin is logged in and this request is in preview mode, we allow the view */ |
54 | 54 | if (!PreviewMode::fromRequest()->check()) { |
55 | - throw new NotFoundHttpException('Model found for request [' . $slug . '] but it is not published.'); |
|
55 | + throw new NotFoundHttpException('Model found for request ['.$slug.'] but it is not published.'); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
66 | - throw new NotFoundHttpException('No url or model found for request [' . $slug . '] for locale [' . $locale . '].'); |
|
66 | + throw new NotFoundHttpException('No url or model found for request ['.$slug.'] for locale ['.$locale.'].'); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | private static function createRedirect(string $url) |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | { |
39 | 39 | // Constraints |
40 | 40 | if (!isset($values['action'])) { |
41 | - throw new \InvalidArgumentException('Set reference array is missing required values for the "action" keys. Given: ' . print_r($values, true)); |
|
41 | + throw new \InvalidArgumentException('Set reference array is missing required values for the "action" keys. Given: '.print_r($values, true)); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | return new static( |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | { |
54 | 54 | $sets = config('chief.sets', []); |
55 | 55 | |
56 | - return collect($sets)->map(function ($set, $key) { |
|
56 | + return collect($sets)->map(function($set, $key) { |
|
57 | 57 | return SetReference::fromArray($key, $set); |
58 | 58 | }); |
59 | 59 | } |
60 | 60 | |
61 | 61 | public static function find($key): ?SetReference |
62 | 62 | { |
63 | - return static::all()->filter(function ($ref) use ($key) { |
|
63 | + return static::all()->filter(function($ref) use ($key) { |
|
64 | 64 | return $ref->key() == $key; |
65 | 65 | })->first(); |
66 | 66 | } |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | private static function validateAction($class, $method) |
153 | 153 | { |
154 | 154 | if (!class_exists($class)) { |
155 | - throw new \InvalidArgumentException('The class [' . $class . '] isn\'t a valid class reference or does not exist in the chief-settings.sets config entry.'); |
|
155 | + throw new \InvalidArgumentException('The class ['.$class.'] isn\'t a valid class reference or does not exist in the chief-settings.sets config entry.'); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | if (!method_exists($class, $method)) { |
159 | - throw new \InvalidArgumentException('The method [' . $method . '] does not exist on the class [' . $class . ']. Make sure you provide a valid method to the action value in the chief-settings.sets config entry.'); |
|
159 | + throw new \InvalidArgumentException('The method ['.$method.'] does not exist on the class ['.$class.']. Make sure you provide a valid method to the action value in the chief-settings.sets config entry.'); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 |
@@ -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\Old\PageBuilder; |
6 | 6 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $availableChildren = AvailableChildren::forParent($model); |
43 | 43 | |
44 | 44 | // Only include modules of this model or shared ones. |
45 | - $modules = $availableChildren->onlyModules()->reject(function ($module) use ($model) { |
|
45 | + $modules = $availableChildren->onlyModules()->reject(function($module) use ($model) { |
|
46 | 46 | return $module->owner_id != null && $module->owner_id != $model->id; |
47 | 47 | }); |
48 | 48 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $available_sets = ModelReferencePresenter::toGroupedSelectValues($availableChildren->onlySets())->toArray(); |
52 | 52 | |
53 | 53 | // Current sections |
54 | - $sections = $model->children()->map(function ($section, $index) use($model) { |
|
54 | + $sections = $model->children()->map(function($section, $index) use($model) { |
|
55 | 55 | // if ($section instanceof TranslatableContract) { |
56 | 56 | // |
57 | 57 | // } |
@@ -88,14 +88,14 @@ discard block |
||
88 | 88 | $trans = []; |
89 | 89 | |
90 | 90 | // Has dynamic attributes |
91 | - if(public_method_exists($model, 'dynamic')) { |
|
91 | + if (public_method_exists($model, 'dynamic')) { |
|
92 | 92 | foreach (config('chief.locales') as $locale) { |
93 | 93 | $trans[$locale] = []; |
94 | 94 | |
95 | - foreach($model->rawDynamicValues() as $key => $values) { |
|
96 | - if(is_array($values)) { |
|
97 | - foreach($values as $dynamicLocale => $dynamicValue) { |
|
98 | - if($dynamicLocale === $locale) { |
|
95 | + foreach ($model->rawDynamicValues() as $key => $values) { |
|
96 | + if (is_array($values)) { |
|
97 | + foreach ($values as $dynamicLocale => $dynamicValue) { |
|
98 | + if ($dynamicLocale === $locale) { |
|
99 | 99 | $trans[$locale][$key] = $dynamicValue; |
100 | 100 | } |
101 | 101 | } |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | } |
106 | 106 | |
107 | 107 | // Astrotomic translatable |
108 | - if($model instanceof Translatable) { |
|
108 | + if ($model instanceof Translatable) { |
|
109 | 109 | foreach (config('chief.locales') as $locale) { |
110 | - if(!isset($trans[$locale])) $trans[$locale] = []; |
|
110 | + if (!isset($trans[$locale])) $trans[$locale] = []; |
|
111 | 111 | |
112 | 112 | $trans[$locale] = array_merge($trans[$locale], $model->getTranslation($locale)->toArray()); |
113 | 113 | } |
@@ -107,7 +107,9 @@ |
||
107 | 107 | // Astrotomic translatable |
108 | 108 | if($model instanceof Translatable) { |
109 | 109 | foreach (config('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 | } |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | { |
29 | 29 | $types = config('chief.menus', []); |
30 | 30 | |
31 | - return collect($types)->map(function ($menu, $key) { |
|
31 | + return collect($types)->map(function($menu, $key) { |
|
32 | 32 | return new static($key, $menu['label'], $menu['view']); |
33 | 33 | }); |
34 | 34 | } |
35 | 35 | |
36 | 36 | public static function find($key): ?self |
37 | 37 | { |
38 | - return static::all()->filter(function ($menu) use ($key) { |
|
38 | + return static::all()->filter(function($menu) use ($key) { |
|
39 | 39 | return $menu->key() == $key; |
40 | 40 | })->first(); |
41 | 41 | } |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | { |
85 | 85 | $menu = []; |
86 | 86 | |
87 | - $this->items()->each(function ($item) use (&$menu) { |
|
87 | + $this->items()->each(function($item) use (&$menu) { |
|
88 | 88 | $menu[] = sprintf('<li><a href="%s">%s</a></li>', $item->url, $item->label); |
89 | 89 | }); |
90 | 90 | |
91 | - return '<ul>' . implode('', $menu) . '</ul>'; |
|
91 | + return '<ul>'.implode('', $menu).'</ul>'; |
|
92 | 92 | } |
93 | 93 | } |
@@ -20,19 +20,19 @@ |
||
20 | 20 | public function update(Request $request) |
21 | 21 | { |
22 | 22 | /** @var ProvidesUrl|Model $model */ |
23 | - $model = (new ModelReference($request->modelClass, (int) $request->modelId))->instance(); |
|
23 | + $model = (new ModelReference($request->modelClass, (int)$request->modelId))->instance(); |
|
24 | 24 | |
25 | 25 | $this->validate($request, ['links' => [ |
26 | - 'array', 'min:1', new UniqueUrlSlugRule($model, $model),], [], ['links.*' => 'taalspecifieke link'] |
|
26 | + 'array', 'min:1', new UniqueUrlSlugRule($model, $model), ], [], ['links.*' => 'taalspecifieke link'] |
|
27 | 27 | ]); |
28 | 28 | |
29 | 29 | (new SaveUrlSlugs())->handle($model, $request->input('links', [])); |
30 | 30 | |
31 | 31 | // Push update to homepage setting value |
32 | 32 | // TODO: we should just fetch the homepages and push that instead... |
33 | - UrlRecord::getByModel($model)->reject(function ($record) { |
|
33 | + UrlRecord::getByModel($model)->reject(function($record) { |
|
34 | 34 | return ($record->isRedirect() || !$record->isHomepage()); |
35 | - })->each(function ($record) { |
|
35 | + })->each(function($record) { |
|
36 | 36 | app(ChangeHomepage::class)->onUrlChanged($record); |
37 | 37 | }); |
38 | 38 |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | private function saveRecord(ProvidesUrl $model, string $locale, ?string $slug, Collection $existingRecords) |
39 | 39 | { |
40 | 40 | // Existing ones for this locale? |
41 | - $nonRedirectsWithSameLocale = $existingRecords->filter(function ($record) use ($locale) { |
|
41 | + $nonRedirectsWithSameLocale = $existingRecords->filter(function($record) use ($locale) { |
|
42 | 42 | return ( |
43 | 43 | $record->locale == $locale && |
44 | 44 | !$record->isRedirect() |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | |
48 | 48 | // If slug entry is left empty, all existing records will be deleted |
49 | 49 | if (!$slug) { |
50 | - $nonRedirectsWithSameLocale->each(function ($existingRecord) { |
|
50 | + $nonRedirectsWithSameLocale->each(function($existingRecord) { |
|
51 | 51 | $existingRecord->delete(); |
52 | 52 | }); |
53 | 53 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | // Only replace the existing records that differ from the current passed slugs |
67 | - $nonRedirectsWithSameLocale->each(function ($existingRecord) use ($slug) { |
|
67 | + $nonRedirectsWithSameLocale->each(function($existingRecord) use ($slug) { |
|
68 | 68 | if ($existingRecord->slug != $slug) { |
69 | 69 | $existingRecord->replaceAndRedirect(['slug' => $slug]); |
70 | 70 | } |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | */ |
106 | 106 | private function deleteIdenticalRedirects($existingRecords, $locale, $slug): void |
107 | 107 | { |
108 | - $existingRecords->filter(function ($record) use ($locale) { |
|
108 | + $existingRecords->filter(function($record) use ($locale) { |
|
109 | 109 | return ( |
110 | 110 | $record->locale == $locale && |
111 | 111 | $record->isRedirect() |
112 | 112 | ); |
113 | - })->each(function ($existingRecord) use ($slug) { |
|
113 | + })->each(function($existingRecord) use ($slug) { |
|
114 | 114 | if ($existingRecord->slug == $slug) { |
115 | 115 | $existingRecord->delete(); |
116 | 116 | } |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | |
126 | 126 | // The old homepage url should be removed since this is no longer in effect. |
127 | 127 | // In case of any redirect to this old homepage, the last used redirect is now back in effect. |
128 | - $existingRecords->reject(function ($existingRecord) { |
|
128 | + $existingRecords->reject(function($existingRecord) { |
|
129 | 129 | return ( |
130 | 130 | $existingRecord->model_type == $model->getMorphClass() && |
131 | 131 | $existingRecord->model_id == $model->id); |
132 | - })->each(function ($existingRecord) { |
|
132 | + })->each(function($existingRecord) { |
|
133 | 133 | |
134 | 134 | // TODO: if there is a redirect to this page, we'll take this one as the new url |
135 | 135 | $existingRecord->delete(); |