@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | public function manager(Manager $manager) |
| 34 | 34 | { |
| 35 | - $this->manager = $manager; |
|
| 35 | + $this->manager = $manager; |
|
| 36 | 36 | |
| 37 | - if(! $manager->model() instanceof ProvidesUrl){ |
|
| 38 | - throw new \Exception('UrlAssistant requires the model interfaced by ' . ProvidesUrl::class . '.'); |
|
| 37 | + if (!$manager->model() instanceof ProvidesUrl) { |
|
| 38 | + throw new \Exception('UrlAssistant requires the model interfaced by '.ProvidesUrl::class.'.'); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | $this->model = $manager->model(); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | InputField::make('url-slugs') |
| 60 | 60 | ->validation( |
| 61 | 61 | [ |
| 62 | - 'url-slugs' => ['array', 'min:1', new UniqueUrlSlugRule(($this->model && $this->model->exists) ? $this->model : null),], |
|
| 62 | + 'url-slugs' => ['array', 'min:1', new UniqueUrlSlugRule(($this->model && $this->model->exists) ? $this->model : null), ], |
|
| 63 | 63 | ], |
| 64 | 64 | [], |
| 65 | 65 | [ |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | 'url-slugs.*' => 'taalspecifieke link', |
| 68 | 68 | ]) |
| 69 | 69 | ->view('chief::back._fields.url-slugs') |
| 70 | - ->viewData(['fields' => UrlSlugFields::fromModel($this->model) ]), |
|
| 70 | + ->viewData(['fields' => UrlSlugFields::fromModel($this->model)]), |
|
| 71 | 71 | ]); |
| 72 | 72 | } |
| 73 | 73 | |
@@ -72,11 +72,11 @@ discard block |
||
| 72 | 72 | $this->filters()->apply($builder); |
| 73 | 73 | |
| 74 | 74 | $results = $builder->get(); |
| 75 | - } else { |
|
| 75 | + }else { |
|
| 76 | 76 | $results = $model::all(); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - return $results->map(function ($model) { |
|
| 79 | + return $results->map(function($model) { |
|
| 80 | 80 | return (new static($this->registration))->manage($model); |
| 81 | 81 | }); |
| 82 | 82 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | public function guard($verb): Manager |
| 146 | 146 | { |
| 147 | - if (! $this->can($verb)) { |
|
| 147 | + if (!$this->can($verb)) { |
|
| 148 | 148 | NotAllowedManagerRoute::notAllowedVerb($verb, $this); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -166,8 +166,8 @@ discard block |
||
| 166 | 166 | { |
| 167 | 167 | $fields = $this->fields(); |
| 168 | 168 | |
| 169 | - foreach($this->assistants() as $assistant){ |
|
| 170 | - if( ! method_exists($assistant, 'fields')) continue; |
|
| 169 | + foreach ($this->assistants() as $assistant) { |
|
| 170 | + if (!method_exists($assistant, 'fields')) continue; |
|
| 171 | 171 | |
| 172 | 172 | $fields = $fields->merge($assistant->fields()); |
| 173 | 173 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | // Could be translatable field |
| 206 | 206 | if ($this->isTranslatableKey($field)) { |
| 207 | - $attribute = substr($field, strrpos($field, '.') + 1); |
|
| 207 | + $attribute = substr($field, strrpos($field, '.')+1); |
|
| 208 | 208 | $locale = substr($field, strlen('trans.'), 2); |
| 209 | 209 | |
| 210 | 210 | return $this->model->getTranslationFor($attribute, $locale); |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | // Make our media fields able to be translatable as well... |
| 244 | 244 | if ($field->ofType(FieldType::MEDIA, FieldType::DOCUMENT)) { |
| 245 | - throw new \Exception('Cannot process the ' . $field->key . ' media field. Currently no support for translatable media files. We should fix this!'); |
|
| 245 | + throw new \Exception('Cannot process the '.$field->key.' media field. Currently no support for translatable media files. We should fix this!'); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // Okay so this is a bit odd but since all translations are expected to be inside the trans |
@@ -167,7 +167,9 @@ |
||
| 167 | 167 | $fields = $this->fields(); |
| 168 | 168 | |
| 169 | 169 | foreach($this->assistants() as $assistant){ |
| 170 | - if( ! method_exists($assistant, 'fields')) continue; |
|
| 170 | + if( ! method_exists($assistant, 'fields')) { |
|
| 171 | + continue; |
|
| 172 | + } |
|
| 171 | 173 | |
| 172 | 174 | $fields = $fields->merge($assistant->fields()); |
| 173 | 175 | } |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | public function validate(array $data) |
| 48 | 48 | { |
| 49 | 49 | foreach($this->fields as $field){ |
| 50 | - $field->validator($data)->validate(); |
|
| 50 | + $field->validator($data)->validate(); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public function first(): ?Field |
| 26 | 26 | { |
| 27 | - if(!$this->any()) return null; |
|
| 27 | + if (!$this->any()) return null; |
|
| 28 | 28 | |
| 29 | 29 | return reset($this->fields); |
| 30 | 30 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | public function validate(array $data) |
| 48 | 48 | { |
| 49 | - foreach($this->fields as $field){ |
|
| 49 | + foreach ($this->fields as $field) { |
|
| 50 | 50 | $field->validator($data)->validate(); |
| 51 | 51 | } |
| 52 | 52 | } |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | public function offsetSet($offset, $value) |
| 123 | 123 | { |
| 124 | - if (! $value instanceof Field) { |
|
| 125 | - throw new \InvalidArgumentException('Passed value must be of type ' . Field::class); |
|
| 124 | + if (!$value instanceof Field) { |
|
| 125 | + throw new \InvalidArgumentException('Passed value must be of type '.Field::class); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | $this->fields[$offset] = $value; |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | { |
| 143 | 143 | $keyedFields = []; |
| 144 | 144 | |
| 145 | - foreach($fields as $field) |
|
| 145 | + foreach ($fields as $field) |
|
| 146 | 146 | { |
| 147 | 147 | $keyedFields[$field->key] = $field; |
| 148 | 148 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | private function validateFields(array $fields) |
| 154 | 154 | { |
| 155 | - array_map(function (Field $field) { |
|
| 155 | + array_map(function(Field $field) { |
|
| 156 | 156 | }, $fields); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -24,7 +24,9 @@ |
||
| 24 | 24 | |
| 25 | 25 | public function first(): ?Field |
| 26 | 26 | { |
| 27 | - if(!$this->any()) return null; |
|
| 27 | + if(!$this->any()) { |
|
| 28 | + return null; |
|
| 29 | + } |
|
| 28 | 30 | |
| 29 | 31 | return reset($this->fields); |
| 30 | 32 | } |
@@ -19,15 +19,15 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public function create(Field $field, array $data): Validator |
| 21 | 21 | { |
| 22 | - if(!$field->hasValidation()){ |
|
| 22 | + if (!$field->hasValidation()) { |
|
| 23 | 23 | return new NullValidator(); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - if($field->validation instanceof Validator){ |
|
| 26 | + if ($field->validation instanceof Validator) { |
|
| 27 | 27 | return $field->validation; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - if($field->validation instanceof \Closure){ |
|
| 30 | + if ($field->validation instanceof \Closure) { |
|
| 31 | 31 | $closure = $field->validation; |
| 32 | 32 | return $closure($this->validatorFactory, $data); |
| 33 | 33 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | private function composeValidatorFromRules(Field $field, array $data): Validator |
| 39 | 39 | { |
| 40 | - if(!is_array($field->validation) || !isset($field->validation[0])){ |
|
| 40 | + if (!is_array($field->validation) || !isset($field->validation[0])) { |
|
| 41 | 41 | throw new \Exception('Invalid validation given. Rules should be passed as non-associative array.'); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -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 | } |