@@ -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\Fields\Types; |
6 | 6 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | public function validation(...$arguments) |
28 | 28 | { |
29 | 29 | // If a Closure or Validator is passed, we do not want to pass it as an array. |
30 | - if(count($arguments) == 1 && !is_array($arguments)){ |
|
30 | + if (count($arguments) == 1 && !is_array($arguments)) { |
|
31 | 31 | $this->values['validation'] = reset($arguments); |
32 | 32 | |
33 | 33 | return $this; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function view(string $view = null) |
94 | 94 | { |
95 | - if($view){ |
|
95 | + if ($view) { |
|
96 | 96 | $this->values['view'] = $view; |
97 | 97 | return $this; |
98 | 98 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | |
103 | 103 | public function viewData(array $viewData = []) |
104 | 104 | { |
105 | - if($viewData){ |
|
105 | + if ($viewData) { |
|
106 | 106 | $this->values['viewData'] = $viewData; |
107 | 107 | return $this; |
108 | 108 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | if (!in_array($name, ['label', 'key', 'description', 'column', 'name', 'prepend', 'append'])) { |
145 | - throw new \InvalidArgumentException('Cannot set value by ['. $name .'].'); |
|
145 | + throw new \InvalidArgumentException('Cannot set value by ['.$name.'].'); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | $this->values[$name] = $arguments[0]; |
@@ -29,15 +29,15 @@ discard block |
||
29 | 29 | try { |
30 | 30 | return view($this->viewPath(), $this->viewData())->render(); |
31 | 31 | } |
32 | - catch(NotFoundView $e) { |
|
33 | - if(config('thinktomorrow.chief.strict')){ |
|
32 | + catch (NotFoundView $e) { |
|
33 | + if (config('thinktomorrow.chief.strict')) { |
|
34 | 34 | throw $e; |
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
38 | 38 | // If no view has been created for this model, we try once again to fetch the content value if any. This will silently fail |
39 | 39 | // if no content value is present. We consider the 'content' attribute to be a default for our copy. |
40 | - return isset($this->content) ? (string) $this->content : ''; |
|
40 | + return isset($this->content) ? (string)$this->content : ''; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | public function setViewParent(ActsAsParent $parent): ViewableContract |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function viewKey(): string |
58 | 58 | { |
59 | - if(property_exists($this, 'viewKey') && isset($this->viewKey)) return $this->viewKey; |
|
59 | + if (property_exists($this, 'viewKey') && isset($this->viewKey)) return $this->viewKey; |
|
60 | 60 | |
61 | - if($this instanceof MorphableContract){ |
|
61 | + if ($this instanceof MorphableContract) { |
|
62 | 62 | return $this->morphKey(); |
63 | 63 | } |
64 | 64 | |
65 | - if(config('thinktomorrow.chief.strict')) { |
|
66 | - throw new NotFoundViewKey('Missing view key. Please add a [viewKey] property to ' . get_class($this)); |
|
65 | + if (config('thinktomorrow.chief.strict')) { |
|
66 | + throw new NotFoundViewKey('Missing view key. Please add a [viewKey] property to '.get_class($this)); |
|
67 | 67 | }; |
68 | 68 | |
69 | 69 | return ''; |
@@ -28,8 +28,7 @@ discard block |
||
28 | 28 | { |
29 | 29 | try { |
30 | 30 | return view($this->viewPath(), $this->viewData())->render(); |
31 | - } |
|
32 | - catch(NotFoundView $e) { |
|
31 | + } catch(NotFoundView $e) { |
|
33 | 32 | if(config('thinktomorrow.chief.strict')){ |
34 | 33 | throw $e; |
35 | 34 | } |
@@ -56,7 +55,9 @@ discard block |
||
56 | 55 | */ |
57 | 56 | public function viewKey(): string |
58 | 57 | { |
59 | - if(property_exists($this, 'viewKey') && isset($this->viewKey)) return $this->viewKey; |
|
58 | + if(property_exists($this, 'viewKey') && isset($this->viewKey)) { |
|
59 | + return $this->viewKey; |
|
60 | + } |
|
60 | 61 | |
61 | 62 | if($this instanceof MorphableContract){ |
62 | 63 | return $this->morphKey(); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function get(): string |
36 | 36 | { |
37 | - $basePath = $this->viewBasePath ? $this->viewBasePath . '.' : ''; |
|
37 | + $basePath = $this->viewBasePath ? $this->viewBasePath.'.' : ''; |
|
38 | 38 | $guessedParentViewName = $this->parent ? $this->parent->viewKey() : ''; |
39 | 39 | $guessedViewName = $this->viewable->viewKey(); |
40 | 40 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | foreach ($viewPaths as $viewPath) { |
56 | - if (! view()->exists($viewPath)) { |
|
56 | + if (!view()->exists($viewPath)) { |
|
57 | 57 | continue; |
58 | 58 | } |
59 | 59 |
@@ -87,11 +87,11 @@ |
||
87 | 87 | return parent::fields()->add( |
88 | 88 | $this->pageBuilderField(), |
89 | 89 | InputField::make('title')->translatable($this->model->availableLocales()) |
90 | - ->validation('required-fallback-locale|max:200', [], [ |
|
91 | - 'trans.'.config('app.fallback_locale', 'nl').'.title' => 'title', |
|
92 | - ]) |
|
93 | - ->label('De titel van je '.$this->model->labelSingular ?? 'pagina') |
|
94 | - ->description('Dit is de titel die zal worden getoond in de overzichten en modules.'), |
|
90 | + ->validation('required-fallback-locale|max:200', [], [ |
|
91 | + 'trans.'.config('app.fallback_locale', 'nl').'.title' => 'title', |
|
92 | + ]) |
|
93 | + ->label('De titel van je '.$this->model->labelSingular ?? 'pagina') |
|
94 | + ->description('Dit is de titel die zal worden getoond in de overzichten en modules.'), |
|
95 | 95 | InputField::make('seo_title') |
96 | 96 | ->translatable($this->model->availableLocales()) |
97 | 97 | ->label('Zoekmachine titel'), |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | { |
61 | 61 | $permission = 'update-page'; |
62 | 62 | |
63 | - if (in_array($verb, ['index','show'])) { |
|
63 | + if (in_array($verb, ['index', 'show'])) { |
|
64 | 64 | $permission = 'view-page'; |
65 | - } elseif (in_array($verb, ['create','store'])) { |
|
65 | + } elseif (in_array($verb, ['create', 'store'])) { |
|
66 | 66 | $permission = 'create-page'; |
67 | 67 | } elseif (in_array($verb, ['delete'])) { |
68 | 68 | $permission = 'delete-page'; |
69 | 69 | } |
70 | 70 | |
71 | - if (! auth()->guard('chief')->user()->hasPermissionTo($permission)) { |
|
71 | + if (!auth()->guard('chief')->user()->hasPermissionTo($permission)) { |
|
72 | 72 | throw NotAllowedManagerRoute::notAllowedPermission($permission, $this); |
73 | 73 | } |
74 | 74 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | public function fieldArrangement($key = null): FieldArrangement |
126 | 126 | { |
127 | 127 | if ($key == 'create') { |
128 | - return new FieldArrangement($this->fieldsWithAssistantFields()->filterBy(function ($field) { |
|
128 | + return new FieldArrangement($this->fieldsWithAssistantFields()->filterBy(function($field) { |
|
129 | 129 | return $field->key == 'title'; |
130 | 130 | })); |
131 | 131 | } |
@@ -144,8 +144,8 @@ discard block |
||
144 | 144 | if ($this->model->id) { |
145 | 145 | return parent::details() |
146 | 146 | ->set('title', $this->model->title) |
147 | - ->set('intro', 'laatst aangepast op ' . $this->model->updated_at->format('d/m/Y H:i')) |
|
148 | - ->set('context', '<span class="inline-s">' . $this->assistant('publish')->publicationStatusAsLabel() . '</span>'); |
|
147 | + ->set('intro', 'laatst aangepast op '.$this->model->updated_at->format('d/m/Y H:i')) |
|
148 | + ->set('context', '<span class="inline-s">'.$this->assistant('publish')->publicationStatusAsLabel().'</span>'); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | return parent::details(); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | public function saveFields(): Manager |
155 | 155 | { |
156 | 156 | // Store the morph_key upon creation |
157 | - if (! $this->model->morph_key) { |
|
157 | + if (!$this->model->morph_key) { |
|
158 | 158 | $this->model->morph_key = $this->model->morphKey(); |
159 | 159 | } |
160 | 160 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | if (is_array_empty($translation)) { |
193 | 193 | |
194 | 194 | // Nullify all values |
195 | - $trans[$locale] = array_map(function ($value) { |
|
195 | + $trans[$locale] = array_map(function($value) { |
|
196 | 196 | return null; |
197 | 197 | }, $translation); |
198 | 198 | continue; |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | { |
74 | 74 | $this->constructWithSnippets(); |
75 | 75 | |
76 | - if(!isset($this->baseViewPath)) { |
|
77 | - $this->baseViewPath = config('thinktomorrow.chief.base-view-paths.pages','pages'); |
|
76 | + if (!isset($this->baseViewPath)) { |
|
77 | + $this->baseViewPath = config('thinktomorrow.chief.base-view-paths.pages', 'pages'); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | parent::__construct($attributes); |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | public function flatReferenceLabel(): string |
118 | 118 | { |
119 | 119 | if ($this->exists) { |
120 | - $status = ! $this->isPublished() ? ' [' . $this->statusAsPlainLabel().']' : null; |
|
120 | + $status = !$this->isPublished() ? ' ['.$this->statusAsPlainLabel().']' : null; |
|
121 | 121 | |
122 | - return $this->title ? $this->title . $status : ''; |
|
122 | + return $this->title ? $this->title.$status : ''; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | return ''; |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | /** @inheritdoc */ |
157 | 157 | public function url(string $locale = null): string |
158 | 158 | { |
159 | - if(!$locale) $locale = app()->getLocale(); |
|
159 | + if (!$locale) $locale = app()->getLocale(); |
|
160 | 160 | |
161 | - try{ |
|
161 | + try { |
|
162 | 162 | $slug = MemoizedUrlRecord::findByModel($this, $locale)->slug; |
163 | 163 | |
164 | 164 | return $this->resolveUrl($locale, [$slug]); |
165 | 165 | } |
166 | - catch(UrlRecordNotFound $e) |
|
166 | + catch (UrlRecordNotFound $e) |
|
167 | 167 | { |
168 | 168 | return ''; |
169 | 169 | } |
@@ -156,14 +156,15 @@ |
||
156 | 156 | /** @inheritdoc */ |
157 | 157 | public function url(string $locale = null): string |
158 | 158 | { |
159 | - if(!$locale) $locale = app()->getLocale(); |
|
159 | + if(!$locale) { |
|
160 | + $locale = app()->getLocale(); |
|
161 | + } |
|
160 | 162 | |
161 | 163 | try{ |
162 | 164 | $slug = MemoizedUrlRecord::findByModel($this, $locale)->slug; |
163 | 165 | |
164 | 166 | return $this->resolveUrl($locale, [$slug]); |
165 | - } |
|
166 | - catch(UrlRecordNotFound $e) |
|
167 | + } catch(UrlRecordNotFound $e) |
|
167 | 168 | { |
168 | 169 | return ''; |
169 | 170 | } |
@@ -24,8 +24,8 @@ discard block |
||
24 | 24 | { |
25 | 25 | $this->viewKey = $viewKey; |
26 | 26 | |
27 | - if(!isset($this->baseViewPath)) { |
|
28 | - $this->baseViewPath = config('thinktomorrow.chief.base-view-paths.sets','sets'); |
|
27 | + if (!isset($this->baseViewPath)) { |
|
28 | + $this->baseViewPath = config('thinktomorrow.chief.base-view-paths.sets', 'sets'); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | $this->constructWithSnippets(); |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | |
41 | 41 | public function renderView(): string |
42 | 42 | { |
43 | - if($result = $this->baseRenderView()){ return $result; } |
|
43 | + if ($result = $this->baseRenderView()) { return $result; } |
|
44 | 44 | |
45 | 45 | // If no view has been created for this page collection, we try once again to fetch the content value if any. This will silently fail |
46 | 46 | // if no content value is present. We don't consider the 'content' attribute to be a default as we do for module. |
47 | - return $this->map(function ($item){ |
|
47 | + return $this->map(function($item) { |
|
48 | 48 | return ($this->viewParent && $item instanceof ViewableContract) |
49 | 49 | ? $item->setViewParent($this->viewParent)->renderView() |
50 | 50 | : ($item->content ?? ''); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | { |
78 | 78 | $currentPage = $currentPage ?? request()->get('page', 1); |
79 | 79 | $path = request()->path(); |
80 | - $items = array_slice($this->all(), ($currentPage - 1) * $perPage); |
|
80 | + $items = array_slice($this->all(), ($currentPage-1) * $perPage); |
|
81 | 81 | |
82 | 82 | return (new \Illuminate\Pagination\Paginator($items, $perPage, $currentPage))->setPath($path); |
83 | 83 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | { |
95 | 95 | $currentPage = $currentPage ?? request()->get('page', 1); |
96 | 96 | $path = request()->path(); |
97 | - $items = array_slice($this->all(), ($currentPage - 1) * $perPage, $perPage); |
|
97 | + $items = array_slice($this->all(), ($currentPage-1) * $perPage, $perPage); |
|
98 | 98 | |
99 | 99 | return (new \Illuminate\Pagination\LengthAwarePaginator($items, $this->count(), $perPage, $currentPage))->setPath($path); |
100 | 100 | } |
@@ -16,9 +16,9 @@ |
||
16 | 16 | public function run(\Closure $closure, array $parameters = []) |
17 | 17 | { |
18 | 18 | // construct cachekey |
19 | - $cachekey = $this->baseKey.':'.md5(implode('',$parameters)); |
|
19 | + $cachekey = $this->baseKey.':'.md5(implode('', $parameters)); |
|
20 | 20 | |
21 | - if(isset(static::$cache[$cachekey])){ |
|
21 | + if (isset(static::$cache[$cachekey])) { |
|
22 | 22 | return static::$cache[$cachekey]; |
23 | 23 | } |
24 | 24 |
@@ -56,8 +56,8 @@ |
||
56 | 56 | { |
57 | 57 | $this->constructWithSnippets(); |
58 | 58 | |
59 | - if(!isset($this->baseViewPath)) { |
|
60 | - $this->baseViewPath = config('thinktomorrow.chief.base-view-paths.modules','modules'); |
|
59 | + if (!isset($this->baseViewPath)) { |
|
60 | + $this->baseViewPath = config('thinktomorrow.chief.base-view-paths.modules', 'modules'); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | parent::__construct($attributes); |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | public static function getByModel(Model $model) |
64 | 64 | { |
65 | 65 | return static::where('model_type', $model->getMorphClass()) |
66 | - ->where('model_id', $model->id) |
|
67 | - ->get(); |
|
66 | + ->where('model_id', $model->id) |
|
67 | + ->get(); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | public function replaceAndRedirect(array $values): UrlRecord |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | if($ignoredModel){ |
118 | 118 | $builder->whereNotIn('id', function($query) use($ignoredModel){ |
119 | 119 | $query->select('id') |
120 | - ->from('chief_urls') |
|
121 | - ->where('model_type', '=', $ignoredModel->getMorphClass()) |
|
122 | - ->where('model_id', '=', $ignoredModel->id); |
|
120 | + ->from('chief_urls') |
|
121 | + ->where('model_type', '=', $ignoredModel->getMorphClass()) |
|
122 | + ->where('model_id', '=', $ignoredModel->id); |
|
123 | 123 | }); |
124 | 124 | } |
125 | 125 |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | public static function findBySlug(string $slug, string $locale): UrlRecord |
23 | 23 | { |
24 | 24 | // Clear the input from any trailing slashes. |
25 | - if($slug != '/'){ $slug = trim($slug,'/'); } |
|
25 | + if ($slug != '/') { $slug = trim($slug, '/'); } |
|
26 | 26 | |
27 | 27 | $record = static::where('slug', $slug) |
28 | 28 | ->where('locale', $locale) |
29 | 29 | ->orderBy('redirect_id', 'ASC') |
30 | 30 | ->first(); |
31 | 31 | |
32 | - if(!$record){ |
|
32 | + if (!$record) { |
|
33 | 33 | throw new UrlRecordNotFound('No url record found by slug ['.$slug.'] for locale ['.$locale.'].'); |
34 | 34 | } |
35 | 35 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | ->orderBy('redirect_id', 'ASC') |
54 | 54 | ->first(); |
55 | 55 | |
56 | - if(!$record){ |
|
56 | + if (!$record) { |
|
57 | 57 | throw new UrlRecordNotFound('No url record found for model ['.$model->getMorphClass().'@'.$model->id.'] for locale ['.$locale.'].'); |
58 | 58 | } |
59 | 59 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | |
83 | 83 | public function redirectTo(self $record = null): ?UrlRecord |
84 | 84 | { |
85 | - if(!$record){ |
|
85 | + if (!$record) { |
|
86 | 86 | return $this->isRedirect() ? static::find($this->redirect_id) : null; |
87 | 87 | } |
88 | 88 | |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | { |
107 | 107 | $builder = static::where('slug', $slug); |
108 | 108 | |
109 | - if($locale) { |
|
109 | + if ($locale) { |
|
110 | 110 | $builder->where('locale', $locale); |
111 | 111 | } |
112 | 112 | |
113 | - if( ! $includeRedirects){ |
|
113 | + if (!$includeRedirects) { |
|
114 | 114 | $builder->whereNull('redirect_id'); |
115 | 115 | } |
116 | 116 | |
117 | - if($ignoredModel){ |
|
117 | + if ($ignoredModel) { |
|
118 | 118 | $builder->whereNotIn('id', function($query) use($ignoredModel){ |
119 | 119 | $query->select('id') |
120 | 120 | ->from('chief_urls') |