@@ -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\Site\Urls\Field; |
| 6 | 6 | |
@@ -19,9 +19,9 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | // Push update to homepage setting value |
| 21 | 21 | // TODO: we should just fetch the homepages and push that instead... |
| 22 | - UrlRecord::getByModel($model)->reject(function ($record) { |
|
| 22 | + UrlRecord::getByModel($model)->reject(function($record) { |
|
| 23 | 23 | return ($record->isRedirect() || !$record->isHomepage()); |
| 24 | - })->each(function ($record) { |
|
| 24 | + })->each(function($record) { |
|
| 25 | 25 | app(ChangeHomepage::class)->onUrlChanged($record); |
| 26 | 26 | }); |
| 27 | 27 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | return $this->fullUrl |
| 44 | 44 | ? $this->fullUrl |
| 45 | - : $this->prepend . $this->getValue(); |
|
| 45 | + : $this->prepend.$this->getValue(); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | public function setFullUrl(string $fullUrl) |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | 'baseUrlSegment' => $this->baseUrlSegment, |
| 95 | 95 | 'hint' => null, // Hint placeholder to show url hint when it already exists |
| 96 | 96 | 'is_homepage' => ($this->getValue() === '/'), |
| 97 | - 'show' => !!$this->getValue(),// show input field or not |
|
| 97 | + 'show' => !!$this->getValue(), // show input field or not |
|
| 98 | 98 | ]; |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | ->first(); |
| 38 | 38 | |
| 39 | 39 | if (!$record) { |
| 40 | - throw new UrlRecordNotFound('No url record found by slug [' . $slug . '] for locale [' . $locale . '].'); |
|
| 40 | + throw new UrlRecordNotFound('No url record found by slug ['.$slug.'] for locale ['.$locale.'].'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | return $record; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | ->first(); |
| 62 | 62 | |
| 63 | 63 | if (!$record) { |
| 64 | - throw new UrlRecordNotFound('No url record found for model [' . $model->getMorphClass() . '@' . $model->id . '] for locale [' . $locale . '].'); |
|
| 64 | + throw new UrlRecordNotFound('No url record found for model ['.$model->getMorphClass().'@'.$model->id.'] for locale ['.$locale.'].'); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | return $record; |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if ($ignoredModel) { |
| 158 | - $builder->whereNotIn('id', function ($query) use ($ignoredModel) { |
|
| 158 | + $builder->whereNotIn('id', function($query) use ($ignoredModel) { |
|
| 159 | 159 | $query->select('id') |
| 160 | 160 | ->from('chief_urls') |
| 161 | 161 | ->where('model_type', '=', $ignoredModel->getMorphClass()) |
@@ -175,11 +175,11 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | // Filter out offline urls... TODO: this should be a state that is owned by the url and not the model. |
| 177 | 177 | // Because of archived pages the mapping can be null so we reject them before we check for online |
| 178 | - return $records->map(function (UrlRecord $urlRecord) { |
|
| 178 | + return $records->map(function(UrlRecord $urlRecord) { |
|
| 179 | 179 | return Morphables::instance($urlRecord->model_type)->find($urlRecord->model_id); |
| 180 | - })->reject(function ($model) { |
|
| 180 | + })->reject(function($model) { |
|
| 181 | 181 | return $model == null; |
| 182 | - })->reject(function (ProvidesUrl $model) { |
|
| 182 | + })->reject(function(ProvidesUrl $model) { |
|
| 183 | 183 | return (method_exists($model, 'isPublished') && !$model->isPublished()); |
| 184 | 184 | }); |
| 185 | 185 | } |
@@ -60,6 +60,6 @@ |
||
| 60 | 60 | */ |
| 61 | 61 | public function message() |
| 62 | 62 | { |
| 63 | - return 'De \'' . $this->failedDetails['slug'] . '\' link wordt in het ' . $this->failedDetails['locale'] . ' al door een andere pagina gebruikt.'; |
|
| 63 | + return 'De \''.$this->failedDetails['slug'].'\' link wordt in het '.$this->failedDetails['locale'].' al door een andere pagina gebruikt.'; |
|
| 64 | 64 | } |
| 65 | 65 | } |
@@ -35,6 +35,6 @@ |
||
| 35 | 35 | /** @inheritdoc */ |
| 36 | 36 | public function baseUrlSegment(string $locale = null): string |
| 37 | 37 | { |
| 38 | - return BaseUrlSegment::find(isset(static::$baseUrlSegment) ? (array) static::$baseUrlSegment : [], $locale); |
|
| 38 | + return BaseUrlSegment::find(isset(static::$baseUrlSegment) ? (array)static::$baseUrlSegment : [], $locale); |
|
| 39 | 39 | } |
| 40 | 40 | } |
@@ -10,8 +10,8 @@ discard block |
||
| 10 | 10 | { |
| 11 | 11 | public static function find(array $segments, string $locale = null) |
| 12 | 12 | { |
| 13 | - if(count($segments) < 1) return '/'; |
|
| 14 | - if(count($segments) == 1) return reset($segments); |
|
| 13 | + if (count($segments) < 1) return '/'; |
|
| 14 | + if (count($segments) == 1) return reset($segments); |
|
| 15 | 15 | |
| 16 | 16 | // Localized value |
| 17 | 17 | if (($key = $locale ?? app()->getlocale()) && isset($segments[$key])) return $segments[$key]; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public static function prepend(ProvidesUrl $model, string $slug, $locale): string |
| 33 | 33 | { |
| 34 | - $slugWithBaseSegment = $model->baseUrlSegment($locale) . '/' . $slug; |
|
| 34 | + $slugWithBaseSegment = $model->baseUrlSegment($locale).'/'.$slug; |
|
| 35 | 35 | $slugWithBaseSegment = trim($slugWithBaseSegment, '/'); |
| 36 | 36 | |
| 37 | 37 | // If slug with base segment is empty string, it means that the passed slug was probably a "/" character. |
@@ -10,14 +10,22 @@ |
||
| 10 | 10 | { |
| 11 | 11 | public static function find(array $segments, string $locale = null) |
| 12 | 12 | { |
| 13 | - if(count($segments) < 1) return '/'; |
|
| 14 | - if(count($segments) == 1) return reset($segments); |
|
| 13 | + if(count($segments) < 1) { |
|
| 14 | + return '/'; |
|
| 15 | + } |
|
| 16 | + if(count($segments) == 1) { |
|
| 17 | + return reset($segments); |
|
| 18 | + } |
|
| 15 | 19 | |
| 16 | 20 | // Localized value |
| 17 | - if (($key = $locale ?? app()->getlocale()) && isset($segments[$key])) return $segments[$key]; |
|
| 21 | + if (($key = $locale ?? app()->getlocale()) && isset($segments[$key])) { |
|
| 22 | + return $segments[$key]; |
|
| 23 | + } |
|
| 18 | 24 | |
| 19 | 25 | // Fallback localized value |
| 20 | - if (($fallback_locale = config('app.fallback_locale')) && isset($segments[$fallback_locale])) return $segments[$fallback_locale]; |
|
| 26 | + if (($fallback_locale = config('app.fallback_locale')) && isset($segments[$fallback_locale])) { |
|
| 27 | + return $segments[$fallback_locale]; |
|
| 28 | + } |
|
| 21 | 29 | |
| 22 | 30 | // Fallback to first entry |
| 23 | 31 | return reset($segments); |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | public static function modelsByType(array $types, Model $ignoredModel = null, bool $online = true) |
| 91 | 91 | { |
| 92 | - $models = chiefMemoize('all-online-models-' . implode('_', $types), function () use ($types, $online) { |
|
| 92 | + $models = chiefMemoize('all-online-models-'.implode('_', $types), function() use ($types, $online) { |
|
| 93 | 93 | $builder = UrlRecord::whereNull('redirect_id') |
| 94 | 94 | ->select('model_type', 'model_id') |
| 95 | 95 | ->groupBy('model_type', 'model_id'); |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | $builder->whereIn('model_type', $types); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - return $builder->get()->mapToGroups(function ($record) { |
|
| 101 | + return $builder->get()->mapToGroups(function($record) { |
|
| 102 | 102 | return [$record->model_type => $record->model_id]; |
| 103 | - })->map(function ($record, $key) { |
|
| 103 | + })->map(function($record, $key) { |
|
| 104 | 104 | return Morphables::instance($key)->find($record->toArray()); |
| 105 | - })->map->reject(function ($model) use ($online) { |
|
| 105 | + })->map->reject(function($model) use ($online) { |
|
| 106 | 106 | if ($online) { |
| 107 | 107 | return is_null($model) || (public_method_exists($model, 'isPublished') && !$model->isPublished()); |
| 108 | 108 | } // Invalid references to archived or removed models where url record still exists. |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | }); |
| 113 | 113 | |
| 114 | 114 | if ($ignoredModel) { |
| 115 | - $models = $models->reject(function ($model) use ($ignoredModel) { |
|
| 115 | + $models = $models->reject(function($model) use ($ignoredModel) { |
|
| 116 | 116 | return (get_class($model) === get_class($ignoredModel) && $model->id === $ignoredModel->id); |
| 117 | 117 | }); |
| 118 | 118 | } |
@@ -23,15 +23,15 @@ |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | foreach ($rules as $key => $rule) { |
| 26 | - $translationrules['trans.' . $locale . '.' . $key] = $rule; |
|
| 26 | + $translationrules['trans.'.$locale.'.'.$key] = $rule; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | foreach ($attributes as $key => $attribute) { |
| 30 | - $translationattributes['trans.' . $locale . '.' . $key] = $attribute; |
|
| 30 | + $translationattributes['trans.'.$locale.'.'.$key] = $attribute; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | foreach ($messages as $key => $message) { |
| 34 | - $translationmessages['trans.' . $locale . '.' . $key] = $message; |
|
| 34 | + $translationmessages['trans.'.$locale.'.'.$key] = $message; |
|
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $available_locales = static::availableLocales(); |
| 147 | 147 | $current_locales = $this->translations->pluck('locale')->toArray(); |
| 148 | 148 | |
| 149 | - return array_filter($available_locales, function ($v) use ($current_locales, $available) { |
|
| 149 | + return array_filter($available_locales, function($v) use ($current_locales, $available) { |
|
| 150 | 150 | return $available ? in_array($v, $current_locales) : !in_array($v, $current_locales); |
| 151 | 151 | }, ARRAY_FILTER_USE_BOTH); |
| 152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | private function validateLocale($locale) |
| 160 | 160 | { |
| 161 | 161 | if (!in_array($locale, static::availableLocales())) { |
| 162 | - throw new InvalidArgumentException('Locale [' . $locale . '] is not available'); |
|
| 162 | + throw new InvalidArgumentException('Locale ['.$locale.'] is not available'); |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |