@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | // 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 |
| 48 | 48 | // if no content value is present. We don't consider the 'content' attribute to be a default as we do for module. |
| 49 | - return $this->map(function ($item) { |
|
| 49 | + return $this->map(function($item) { |
|
| 50 | 50 | return ($this->viewParent && $item instanceof ViewableContract) |
| 51 | 51 | ? $item->setViewParent($this->viewParent)->renderView() |
| 52 | 52 | : ($item->content ?? ''); |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | { |
| 80 | 80 | $currentPage = $currentPage ?? request()->get('page', 1); |
| 81 | 81 | $path = request()->path(); |
| 82 | - $items = array_slice($this->all(), ($currentPage - 1) * $perPage); |
|
| 82 | + $items = array_slice($this->all(), ($currentPage-1) * $perPage); |
|
| 83 | 83 | |
| 84 | 84 | return (new \Illuminate\Pagination\Paginator($items, $perPage, $currentPage))->setPath($path); |
| 85 | 85 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | { |
| 97 | 97 | $currentPage = $currentPage ?? request()->get('page', 1); |
| 98 | 98 | $path = request()->path(); |
| 99 | - $items = array_slice($this->all(), ($currentPage - 1) * $perPage, $perPage); |
|
| 99 | + $items = array_slice($this->all(), ($currentPage-1) * $perPage, $perPage); |
|
| 100 | 100 | |
| 101 | 101 | return (new \Illuminate\Pagination\LengthAwarePaginator($items, $this->count(), $perPage, $currentPage))->setPath($path); |
| 102 | 102 | } |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | public static function getByModel(Model $model) |
| 66 | 66 | { |
| 67 | 67 | return static::where('model_type', $model->getMorphClass()) |
| 68 | - ->where('model_id', $model->id) |
|
| 69 | - ->get(); |
|
| 68 | + ->where('model_id', $model->id) |
|
| 69 | + ->get(); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | public function replaceAndRedirect(array $values): UrlRecord |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | if ($ignoredModel) { |
| 120 | 120 | $builder->whereNotIn('id', function ($query) use ($ignoredModel) { |
| 121 | 121 | $query->select('id') |
| 122 | - ->from('chief_urls') |
|
| 123 | - ->where('model_type', '=', $ignoredModel->getMorphClass()) |
|
| 124 | - ->where('model_id', '=', $ignoredModel->id); |
|
| 122 | + ->from('chief_urls') |
|
| 123 | + ->where('model_type', '=', $ignoredModel->getMorphClass()) |
|
| 124 | + ->where('model_id', '=', $ignoredModel->id); |
|
| 125 | 125 | }); |
| 126 | 126 | } |
| 127 | 127 | |
@@ -112,12 +112,12 @@ |
||
| 112 | 112 | $builder->where('locale', $locale); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if (! $includeRedirects) { |
|
| 115 | + if (!$includeRedirects) { |
|
| 116 | 116 | $builder->whereNull('redirect_id'); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | if ($ignoredModel) { |
| 120 | - $builder->whereNotIn('id', function ($query) use ($ignoredModel) { |
|
| 120 | + $builder->whereNotIn('id', function($query) use ($ignoredModel) { |
|
| 121 | 121 | $query->select('id') |
| 122 | 122 | ->from('chief_urls') |
| 123 | 123 | ->where('model_type', '=', $ignoredModel->getMorphClass()) |
@@ -8,14 +8,14 @@ |
||
| 8 | 8 | { |
| 9 | 9 | public static function findByModel(Model $model, string $locale = null): UrlRecord |
| 10 | 10 | { |
| 11 | - return chiefMemoize('url-records-find-by-model', function ($model, $locale = null) { |
|
| 11 | + return chiefMemoize('url-records-find-by-model', function($model, $locale = null) { |
|
| 12 | 12 | return parent::findByModel($model, $locale); |
| 13 | 13 | }, [$model, $locale]); |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public static function getByModel(Model $model) |
| 17 | 17 | { |
| 18 | - return chiefMemoize('url-records-get-by-model', function ($model) { |
|
| 18 | + return chiefMemoize('url-records-get-by-model', function($model) { |
|
| 19 | 19 | return parent::getByModel($model); |
| 20 | 20 | }, [$model]); |
| 21 | 21 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | private function saveRecord(string $locale, ?string $slug) |
| 40 | 40 | { |
| 41 | 41 | // Existing ones for this locale? |
| 42 | - $nonRedirectsWithSameLocale = $this->existingRecords->filter(function ($record) use ($locale) { |
|
| 42 | + $nonRedirectsWithSameLocale = $this->existingRecords->filter(function($record) use ($locale) { |
|
| 43 | 43 | return ( |
| 44 | 44 | $record->locale == $locale && |
| 45 | 45 | !$record->isRedirect() |
@@ -55,14 +55,14 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | // If slug entry is left empty, all existing records will be deleted |
| 57 | 57 | if (!$slug) { |
| 58 | - $nonRedirectsWithSameLocale->each(function ($existingRecord) { |
|
| 58 | + $nonRedirectsWithSameLocale->each(function($existingRecord) { |
|
| 59 | 59 | $existingRecord->delete(); |
| 60 | 60 | }); |
| 61 | 61 | } elseif ($nonRedirectsWithSameLocale->isEmpty()) { |
| 62 | 62 | $this->createRecord($locale, $slug); |
| 63 | - } else { |
|
| 63 | + }else { |
|
| 64 | 64 | // Only replace the existing records that differ from the current passed slugs |
| 65 | - $nonRedirectsWithSameLocale->each(function ($existingRecord) use ($slug) { |
|
| 65 | + $nonRedirectsWithSameLocale->each(function($existingRecord) use ($slug) { |
|
| 66 | 66 | if ($existingRecord->slug != $slug) { |
| 67 | 67 | $existingRecord->replaceAndRedirect(['slug' => $slug]); |
| 68 | 68 | } |
@@ -87,12 +87,12 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | private function deleteIdenticalRedirects($existingRecords, $locale, $slug): void |
| 89 | 89 | { |
| 90 | - $existingRecords->filter(function ($record) use ($locale) { |
|
| 90 | + $existingRecords->filter(function($record) use ($locale) { |
|
| 91 | 91 | return ( |
| 92 | 92 | $record->locale == $locale && |
| 93 | 93 | $record->isRedirect() |
| 94 | 94 | ); |
| 95 | - })->each(function ($existingRecord) use ($slug) { |
|
| 95 | + })->each(function($existingRecord) use ($slug) { |
|
| 96 | 96 | if ($existingRecord->slug == $slug) { |
| 97 | 97 | $existingRecord->delete(); |
| 98 | 98 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | private function prependBaseUrlSegment(string $slug, $locale): string |
| 108 | 108 | { |
| 109 | - $slugWithBaseSegment = $this->model->baseUrlSegment($locale) . '/' . $slug; |
|
| 109 | + $slugWithBaseSegment = $this->model->baseUrlSegment($locale).'/'.$slug; |
|
| 110 | 110 | $slugWithBaseSegment = trim($slugWithBaseSegment, '/'); |
| 111 | 111 | |
| 112 | 112 | // If slug with base segment is empty string, it means that the passed slug was probably a "/" character. |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | $fields = new static([]); |
| 43 | 43 | |
| 44 | 44 | foreach ($locales as $locale) { |
| 45 | - $fields['url-slugs.' . $locale] = UrlSlugField::make('url-slugs.' . $locale) |
|
| 45 | + $fields['url-slugs.'.$locale] = UrlSlugField::make('url-slugs.'.$locale) |
|
| 46 | 46 | ->setBaseUrlSegment($model->baseUrlSegment($locale)) |
| 47 | - ->prepend($model->resolveUrl($locale, $model->baseUrlSegment($locale)) .'/') |
|
| 48 | - ->name('url-slugs[' . $locale . ']') |
|
| 47 | + ->prepend($model->resolveUrl($locale, $model->baseUrlSegment($locale)).'/') |
|
| 48 | + ->name('url-slugs['.$locale.']') |
|
| 49 | 49 | ->label($locale); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | private static function fillWithExistingValues(ProvidesUrl $model, self $fields): void |
| 60 | 60 | { |
| 61 | - $records = MemoizedUrlRecord::getByModel($model)->reject(function ($record) { |
|
| 61 | + $records = MemoizedUrlRecord::getByModel($model)->reject(function($record) { |
|
| 62 | 62 | return $record->isRedirect(); |
| 63 | 63 | })->sortBy('locale'); |
| 64 | 64 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $fields['url-slugs.'.$record->locale] |
| 71 | 71 | ->setUrlRecord($record) |
| 72 | 72 | ->setBaseUrlSegment($model->baseUrlSegment($record->locale)) |
| 73 | - ->prepend($model->resolveUrl($record->locale, $model->baseUrlSegment($record->locale)) .'/'); |
|
| 73 | + ->prepend($model->resolveUrl($record->locale, $model->baseUrlSegment($record->locale)).'/'); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -39,11 +39,11 @@ discard block |
||
| 39 | 39 | return static::createRedirect($model->url($locale)); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - if (method_exists($model, 'isPublished') && ! $model->isPublished()) { |
|
| 42 | + if (method_exists($model, 'isPublished') && !$model->isPublished()) { |
|
| 43 | 43 | |
| 44 | 44 | /** When admin is logged in and this request is in preview mode, we allow the view */ |
| 45 | - if (! PreviewMode::fromRequest()->check()) { |
|
| 46 | - throw new NotFoundHttpException('Model found for request ['. $slug .'] but it is not published.'); |
|
| 45 | + if (!PreviewMode::fromRequest()->check()) { |
|
| 46 | + throw new NotFoundHttpException('Model found for request ['.$slug.'] but it is not published.'); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - throw new NotFoundHttpException('No url or model found for request ['. $slug .'] for locale ['.$locale.'].'); |
|
| 57 | + throw new NotFoundHttpException('No url or model found for request ['.$slug.'] for locale ['.$locale.'].'); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | private static function createRedirect(string $url) |
@@ -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 | |
@@ -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]; |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | public function offsetSet($offset, $value) |
| 125 | 125 | { |
| 126 | - if (! $value instanceof Field) { |
|
| 127 | - throw new \InvalidArgumentException('Passed value must be of type ' . Field::class); |
|
| 126 | + if (!$value instanceof Field) { |
|
| 127 | + throw new \InvalidArgumentException('Passed value must be of type '.Field::class); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | $this->fields[$offset] = $value; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | private function validateFields(array $fields) |
| 155 | 155 | { |
| 156 | - array_map(function (Field $field) { |
|
| 156 | + array_map(function(Field $field) { |
|
| 157 | 157 | }, $fields); |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -117,9 +117,9 @@ |
||
| 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 ''; |