@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | public function find(string $key): Field |
| 42 | 42 | { |
| 43 | - if(!isset($this->fields[$key])) { |
|
| 44 | - throw new \InvalidArgumentException('No field found by key ' . $key); |
|
| 43 | + if (!isset($this->fields[$key])) { |
|
| 44 | + throw new \InvalidArgumentException('No field found by key '.$key); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | return $this->fields[$key]; |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | continue; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $method = 'get' . ucfirst($key); |
|
| 111 | + $method = 'get'.ucfirst($key); |
|
| 112 | 112 | |
| 113 | 113 | // Reject from list if value does not match expected one |
| 114 | 114 | if ($value && $value == $field->$method()) { |
@@ -124,23 +124,23 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | public function render(): string |
| 126 | 126 | { |
| 127 | - return array_reduce($this->fields, function (string $carry, Field $field) { |
|
| 128 | - return $carry . $field->render(); |
|
| 127 | + return array_reduce($this->fields, function(string $carry, Field $field) { |
|
| 128 | + return $carry.$field->render(); |
|
| 129 | 129 | }, ''); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | public function keyed($key): Fields |
| 133 | 133 | { |
| 134 | - $keys = (array) $key; |
|
| 134 | + $keys = (array)$key; |
|
| 135 | 135 | |
| 136 | - return new static(array_filter($this->fields, function (Field $field) use ($keys) { |
|
| 136 | + return new static(array_filter($this->fields, function(Field $field) use ($keys) { |
|
| 137 | 137 | return in_array($field->getKey(), $keys); |
| 138 | 138 | })); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | public function tagged($tag): Fields |
| 142 | 142 | { |
| 143 | - return new static(array_filter($this->fields, function (Field $field) use ($tag) { |
|
| 143 | + return new static(array_filter($this->fields, function(Field $field) use ($tag) { |
|
| 144 | 144 | return $field->tagged($tag); |
| 145 | 145 | })); |
| 146 | 146 | } |
@@ -148,14 +148,14 @@ discard block |
||
| 148 | 148 | public function notTagged($tag): Fields |
| 149 | 149 | { |
| 150 | 150 | // TODO: to test this... |
| 151 | - return new static(array_filter($this->fields, function (Field $field) use ($tag) { |
|
| 151 | + return new static(array_filter($this->fields, function(Field $field) use ($tag) { |
|
| 152 | 152 | return !$field->tagged($tag); |
| 153 | 153 | })); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | public function untagged(): Fields |
| 157 | 157 | { |
| 158 | - return new static(array_filter($this->fields, function (Field $field) { |
|
| 158 | + return new static(array_filter($this->fields, function(Field $field) { |
|
| 159 | 159 | return $field->untagged(); |
| 160 | 160 | })); |
| 161 | 161 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | public function offsetGet($offset) |
| 198 | 198 | { |
| 199 | 199 | if (!isset($this->fields[$offset])) { |
| 200 | - throw new \RuntimeException('No field found by key [' . $offset . ']'); |
|
| 200 | + throw new \RuntimeException('No field found by key ['.$offset.']'); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | return $this->fields[$offset]; |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | public function offsetSet($offset, $value) |
| 207 | 207 | { |
| 208 | 208 | if (!$value instanceof Field) { |
| 209 | - throw new \InvalidArgumentException('Passed value must be of type ' . Field::class); |
|
| 209 | + throw new \InvalidArgumentException('Passed value must be of type '.Field::class); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | $this->fields[$offset] = $value; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | private function validateFields(array $fields) |
| 238 | 238 | { |
| 239 | - array_map(function (Field $field) { |
|
| 239 | + array_map(function(Field $field) { |
|
| 240 | 240 | }, $fields); |
| 241 | 241 | } |
| 242 | 242 | |
@@ -22,12 +22,12 @@ |
||
| 22 | 22 | |
| 23 | 23 | public function handle($sourceModel, $targetModel): void |
| 24 | 24 | { |
| 25 | - if(!$sourceModel instanceof FragmentsOwner || !$context = ContextModel::ownedBy($sourceModel)) return; |
|
| 25 | + if (!$sourceModel instanceof FragmentsOwner || !$context = ContextModel::ownedBy($sourceModel)) return; |
|
| 26 | 26 | |
| 27 | 27 | $copiedContext = ContextModel::createForOwner($targetModel); |
| 28 | 28 | |
| 29 | 29 | /** @var FragmentModel $fragment */ |
| 30 | - foreach($context->fragments as $fragment) { |
|
| 30 | + foreach ($context->fragments as $fragment) { |
|
| 31 | 31 | $copiedFragment = $fragment->replicate(['context_id']); |
| 32 | 32 | $copiedFragment->id = $this->fragmentRepository->nextId(); |
| 33 | 33 | $copiedFragment->context_id = $copiedContext->id; |
@@ -22,7 +22,9 @@ |
||
| 22 | 22 | |
| 23 | 23 | public function handle($sourceModel, $targetModel): void |
| 24 | 24 | { |
| 25 | - if(!$sourceModel instanceof FragmentsOwner || !$context = ContextModel::ownedBy($sourceModel)) return; |
|
| 25 | + if(!$sourceModel instanceof FragmentsOwner || !$context = ContextModel::ownedBy($sourceModel)) { |
|
| 26 | + return; |
|
| 27 | + } |
|
| 26 | 28 | |
| 27 | 29 | $copiedContext = ContextModel::createForOwner($targetModel); |
| 28 | 30 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public function routeModuleCrudAssistant(string $action, $model = null, ...$parameters): ?string |
| 32 | 32 | { |
| 33 | - if(!in_array($action, ['create','store'])) return null; |
|
| 33 | + if (!in_array($action, ['create', 'store'])) return null; |
|
| 34 | 34 | |
| 35 | 35 | return $this->generateRoute($action, $model, ... $parameters); |
| 36 | 36 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $model->saveFields($model->fields()->tagged('create'), $request->all(), $request->allFiles()); |
| 60 | 60 | |
| 61 | 61 | return redirect()->to($this->route('edit', $model)) |
| 62 | - ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "' . $model->adminLabel('title') . '" is toegevoegd'); |
|
| 62 | + ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "'.$model->adminLabel('title').'" is toegevoegd'); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | public function edit($id) |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | return view('chief::back.managers.edit', [ |
| 75 | 75 | 'manager' => $this, |
| 76 | 76 | 'model' => $model, |
| 77 | - 'fields' => $model->fields()->map(function (Field $field) use ($model) { |
|
| 77 | + 'fields' => $model->fields()->map(function(Field $field) use ($model) { |
|
| 78 | 78 | // TODO refactor so render method of field takes model and managerViewModel as arguments. |
| 79 | 79 | return $field->model($model); |
| 80 | 80 | }), |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $model->saveFields($model->fields(), $request->all(), $request->allFiles()); |
| 94 | 94 | |
| 95 | 95 | return redirect()->to($this->route('edit', $model)) |
| 96 | - ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "' . $model->adminLabel('title') . '" is aangepast'); |
|
| 96 | + ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "'.$model->adminLabel('title').'" is aangepast'); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | public function delete($id, Request $request) |
@@ -103,12 +103,12 @@ discard block |
||
| 103 | 103 | $model = $this->managedModelClass()::findOrFail($id); |
| 104 | 104 | |
| 105 | 105 | if ($request->get('deleteconfirmation') !== 'DELETE') { |
| 106 | - return redirect()->back()->with('messages.warning', $model->adminLabel('title') . ' is niet verwijderd.'); |
|
| 106 | + return redirect()->back()->with('messages.warning', $model->adminLabel('title').' is niet verwijderd.'); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | app(DeleteModel::class)->handle($model); |
| 110 | 110 | |
| 111 | 111 | return redirect()->to($this->route('index')) |
| 112 | - ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "' . $model->adminLabel('title') . '" is verwijderd.'); |
|
| 112 | + ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "'.$model->adminLabel('title').'" is verwijderd.'); |
|
| 113 | 113 | } |
| 114 | 114 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | public function canCrudAssistant(string $action, $model = null): bool |
| 39 | 39 | { |
| 40 | - if(!in_array($action, ['index', 'create', 'store', 'edit', 'update', 'delete'])) return false; |
|
| 40 | + if (!in_array($action, ['index', 'create', 'store', 'edit', 'update', 'delete'])) return false; |
|
| 41 | 41 | |
| 42 | 42 | try { |
| 43 | 43 | |
@@ -56,12 +56,12 @@ discard block |
||
| 56 | 56 | return false; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if(in_array($action, ['index', 'create', 'store'])) return true; |
|
| 59 | + if (in_array($action, ['index', 'create', 'store'])) return true; |
|
| 60 | 60 | |
| 61 | - if(!$model || !$model instanceof StatefulContract) return true; |
|
| 61 | + if (!$model || !$model instanceof StatefulContract) return true; |
|
| 62 | 62 | |
| 63 | 63 | // Model cannot be in deleted state for editing purposes. |
| 64 | - if(in_array($action, ['edit', 'update'])) { |
|
| 64 | + if (in_array($action, ['edit', 'update'])) { |
|
| 65 | 65 | return !($model->stateOf(PageState::KEY) == PageState::DELETED); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -99,14 +99,14 @@ discard block |
||
| 99 | 99 | // Default sorted by publish date |
| 100 | 100 | $modelClass = $this->managedModelClass(); |
| 101 | 101 | if (Schema::hasColumn((new $modelClass)->getTable(), 'published_at')) { |
| 102 | - $filters = $filters->add(HiddenFilter::make('publish', function ($query) { |
|
| 102 | + $filters = $filters->add(HiddenFilter::make('publish', function($query) { |
|
| 103 | 103 | return $query->orderBy('published_at', 'DESC'); |
| 104 | 104 | })); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // if model has no timestamps, updated_at doesn't exist |
| 108 | 108 | if ((new $modelClass)->timestamps) { |
| 109 | - $filters = $filters->add(HiddenFilter::make('updated', function ($query) { |
|
| 109 | + $filters = $filters->add(HiddenFilter::make('updated', function($query) { |
|
| 110 | 110 | return $query->orderBy('updated_at', 'DESC'); |
| 111 | 111 | })); |
| 112 | 112 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | $model->saveFields($model->fields()->notTagged('edit'), $request->all(), $request->allFiles()); |
| 141 | 141 | |
| 142 | 142 | return redirect()->to($this->route('edit', $model)) |
| 143 | - ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "' . $model->adminLabel('title') . '" is toegevoegd'); |
|
| 143 | + ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "'.$model->adminLabel('title').'" is toegevoegd'); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | public function edit(Request $request, $id) |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | $model->saveFields($model->fields()->notTagged('create'), $request->all(), $request->allFiles()); |
| 168 | 168 | |
| 169 | 169 | return redirect()->to($this->route('index')) |
| 170 | - ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> <a href="' . $this->route('edit', $model) . '">' . $model->adminLabel('title') . '</a> is aangepast'); |
|
| 170 | + ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> <a href="'.$this->route('edit', $model).'">'.$model->adminLabel('title').'</a> is aangepast'); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | public function delete(Request $request, $id) |
@@ -177,12 +177,12 @@ discard block |
||
| 177 | 177 | $this->guard('delete', $model); |
| 178 | 178 | |
| 179 | 179 | if ($request->get('deleteconfirmation') !== 'DELETE') { |
| 180 | - return redirect()->back()->with('messages.warning', $model->adminLabel('title') . ' is niet verwijderd.'); |
|
| 180 | + return redirect()->back()->with('messages.warning', $model->adminLabel('title').' is niet verwijderd.'); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | app(DeleteModel::class)->handle($model); |
| 184 | 184 | |
| 185 | 185 | return redirect()->to($this->route('index')) |
| 186 | - ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "' . $model->adminLabel('title') . '" is verwijderd.'); |
|
| 186 | + ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "'.$model->adminLabel('title').'" is verwijderd.'); |
|
| 187 | 187 | } |
| 188 | 188 | } |
@@ -31,18 +31,18 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function routeFragmentAssistant(string $action, $model = null, ...$parameters): ?string |
| 33 | 33 | { |
| 34 | - if(!in_array($action, ['fragment-edit','fragment-update','fragment-delete','fragment-create','fragment-store'])) { |
|
| 34 | + if (!in_array($action, ['fragment-edit', 'fragment-update', 'fragment-delete', 'fragment-create', 'fragment-store'])) { |
|
| 35 | 35 | return null; |
| 36 | 36 | }; |
| 37 | 37 | |
| 38 | 38 | $modelKey = $this->managedModelClass()::managedModelKey(); |
| 39 | 39 | |
| 40 | - if(in_array($action, ['fragment-create', 'fragment-store'])) { |
|
| 40 | + if (in_array($action, ['fragment-create', 'fragment-store'])) { |
|
| 41 | 41 | if (!$model || !$model instanceof FragmentsOwner) { |
| 42 | 42 | throw new \Exception('Fragment route definition for '.$action.' requires the owning Model as second argument.'); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - return route('chief.' . $modelKey . '.' . $action, array_merge([ |
|
| 45 | + return route('chief.'.$modelKey.'.'.$action, array_merge([ |
|
| 46 | 46 | $model::managedModelKey(), |
| 47 | 47 | $model->modelReference()->id(), |
| 48 | 48 | ], $parameters)); |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | throw new \Exception('Fragment route definition for '.$action.' requires the fragment model as second argument.'); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - return route('chief.' . $modelKey . '.' . $action, $model->fragmentModel()->id); |
|
| 55 | + return route('chief.'.$modelKey.'.'.$action, $model->fragmentModel()->id); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | public function canFragmentAssistant(string $action, $model = null): bool |
| 59 | 59 | { |
| 60 | - return in_array($action, ['fragment-edit','fragment-update','fragment-delete','fragment-create','fragment-store']); |
|
| 60 | + return in_array($action, ['fragment-edit', 'fragment-update', 'fragment-delete', 'fragment-create', 'fragment-store']); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public function fragmentCreate(Request $request, string $ownerKey, $ownerId) |
@@ -144,13 +144,13 @@ discard block |
||
| 144 | 144 | $model = $this->managedModelClass()::findOrFail($id); |
| 145 | 145 | |
| 146 | 146 | if ($request->get('deleteconfirmation') !== 'DELETE') { |
| 147 | - return redirect()->back()->with('messages.warning', $model->adminLabel('title') . ' is niet verwijderd.'); |
|
| 147 | + return redirect()->back()->with('messages.warning', $model->adminLabel('title').' is niet verwijderd.'); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | app(DeleteModel::class)->handle($model); |
| 151 | 151 | |
| 152 | 152 | return redirect()->to($this->route('index')) |
| 153 | - ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "' . $model->adminLabel('title') . '" is verwijderd.'); |
|
| 153 | + ->with('messages.success', '<i class="fa fa-fw fa-check-circle"></i> "'.$model->adminLabel('title').'" is verwijderd.'); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | private function owner(string $ownerKey, $ownerId): FragmentsOwner |