@@ -24,7 +24,7 @@ |
||
| 24 | 24 | ], $fragment->getValues()); |
| 25 | 25 | |
| 26 | 26 | if ($fragment->hasModelId()) { |
| 27 | - $model =FragmentModel::find($fragment->getModelId()); |
|
| 27 | + $model = FragmentModel::find($fragment->getModelId()); |
|
| 28 | 28 | $model->update($values); |
| 29 | 29 | |
| 30 | 30 | return $model->id; |
@@ -33,12 +33,12 @@ discard block |
||
| 33 | 33 | // TODO: how to assign for pagebuilder?? with tag, via the chief relations config or is this default |
| 34 | 34 | $moduleManagerClasses = $this->registry->tagged('module')->get(); |
| 35 | 35 | trap('working on it'); |
| 36 | - $managers = collect(array_map(function($moduleManagerClass){ |
|
| 36 | + $managers = collect(array_map(function($moduleManagerClass) { |
|
| 37 | 37 | return app($moduleManagerClass); |
| 38 | 38 | }, $moduleManagerClasses)); |
| 39 | 39 | |
| 40 | 40 | return $managers |
| 41 | - ->reject(function($manager){ return !$manager->can('create'); }) |
|
| 41 | + ->reject(function($manager) { return !$manager->can('create'); }) |
|
| 42 | 42 | ->map(function($manager) { |
| 43 | 43 | return [ |
| 44 | 44 | 'label' => $manager->adminLabel('page_title'), |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | // Get the modules that are set to be shareable. |
| 54 | 54 | $moduleManagerClasses = $this->shareableModules(); |
| 55 | 55 | |
| 56 | - $managers = collect(array_map(function($moduleManagerClass){ |
|
| 56 | + $managers = collect(array_map(function($moduleManagerClass) { |
|
| 57 | 57 | return app($moduleManagerClass); |
| 58 | 58 | }, $moduleManagerClasses)); |
| 59 | 59 | |
| 60 | 60 | return $managers |
| 61 | - ->reject(function($manager){ return !$manager->can('create-shared'); }) |
|
| 62 | - ->map(function($manager){ |
|
| 61 | + ->reject(function($manager) { return !$manager->can('create-shared'); }) |
|
| 62 | + ->map(function($manager) { |
|
| 63 | 63 | return [ |
| 64 | 64 | 'label' => $manager->adminLabel('page_title'), |
| 65 | 65 | 'value' => $manager->route('create-shared') |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | public function create(FragmentsOwner $owner, Fragmentable $fragmentable, int $order, array $data = []): FragmentModel |
| 31 | 31 | { |
| 32 | - if(!$context = ContextModel::ownedBy($owner)) { |
|
| 32 | + if (!$context = ContextModel::ownedBy($owner)) { |
|
| 33 | 33 | $context = ContextModel::createForOwner($owner); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | public function render(Collection $fragmentables, FragmentsOwner $owner, $viewData = []): string |
| 16 | 16 | { |
| 17 | 17 | // Validate each entry as a valid fragment object. |
| 18 | - $fragmentables->each(function(Fragmentable $fragmentable){}); |
|
| 18 | + $fragmentables->each(function(Fragmentable $fragmentable) {}); |
|
| 19 | 19 | |
| 20 | 20 | // Init new loop object |
| 21 | 21 | $this->loopsStack = []; $this->addLoop($fragmentables); |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | $this->incrementLoopIndices(); |
| 25 | 25 | $loop = $this->getLastLoop(); |
| 26 | 26 | |
| 27 | - return $carry . $fragmentable->renderFragment($owner, $loop, $fragmentables, $viewData); |
|
| 27 | + return $carry.$fragmentable->renderFragment($owner, $loop, $fragmentables, $viewData); |
|
| 28 | 28 | }, ''); |
| 29 | 29 | } |
| 30 | 30 | } |
@@ -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 | |