@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | } |
42 | 42 | |
43 | 43 | // Custom set methods - default is the generic setField() method. |
44 | - $methodName = 'set' . ucfirst(Str::camel($field->getKey())) . 'Field'; |
|
44 | + $methodName = 'set'.ucfirst(Str::camel($field->getKey())).'Field'; |
|
45 | 45 | (method_exists($this, $methodName)) |
46 | 46 | ? $this->$methodName($field, $request) |
47 | 47 | : $this->setField($field, $request); |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | |
59 | 59 | protected function detectCustomSaveMethods(Field $field): bool |
60 | 60 | { |
61 | - $saveMethodByKey = 'save' . ucfirst(Str::camel($field->getKey())) . 'Field'; |
|
62 | - $saveMethodByType = 'save' . ucfirst(Str::camel($field->getType()->get())) . 'Fields'; |
|
61 | + $saveMethodByKey = 'save'.ucfirst(Str::camel($field->getKey())).'Field'; |
|
62 | + $saveMethodByType = 'save'.ucfirst(Str::camel($field->getType()->get())).'Fields'; |
|
63 | 63 | |
64 | 64 | foreach ([$saveMethodByKey, $saveMethodByType] as $saveMethod) { |
65 | 65 | foreach ($this->assistants() as $assistant) { |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | // Make our media fields able to be translatable as well... |
109 | 109 | if ($field->ofType(FieldType::FILE, FieldType::IMAGE)) { |
110 | - throw new \Exception('Cannot process the ' . $field->getKey() . ' media field. Currently no support for translatable media files. We should fix this!'); |
|
110 | + throw new \Exception('Cannot process the '.$field->getKey().' media field. Currently no support for translatable media files. We should fix this!'); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | // Okay so this is a bit odd but since all translations are expected to be inside the trans |
@@ -160,6 +160,6 @@ discard block |
||
160 | 160 | |
161 | 161 | public function saveImageFields(ImageField $field, Request $request) |
162 | 162 | { |
163 | - app(ImageFieldHandler::class)->handle($this->model, $field, $request->input('images.' . $field->getName(), []), $request); |
|
163 | + app(ImageFieldHandler::class)->handle($this->model, $field, $request->input('images.'.$field->getName(), []), $request); |
|
164 | 164 | } |
165 | 165 | } |
@@ -22,11 +22,11 @@ discard block |
||
22 | 22 | return false; |
23 | 23 | } |
24 | 24 | |
25 | - if(in_array($key, $this->dynamicKeys())) { |
|
25 | + if (in_array($key, $this->dynamicKeys())) { |
|
26 | 26 | return true; |
27 | 27 | } |
28 | 28 | |
29 | - if(in_array('*', $this->dynamicKeys())){ |
|
29 | + if (in_array('*', $this->dynamicKeys())) { |
|
30 | 30 | return !in_array($key, $this->dynamicKeysBlacklist()); |
31 | 31 | } |
32 | 32 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $value = $this->dynamic($key); |
114 | 114 | |
115 | 115 | // If value is localized, we wont return the entire value, but instead return null since no fallback will be provided. |
116 | - if(is_array($value) && in_array($locale, $this->dynamicLocales())) return null; |
|
116 | + if (is_array($value) && in_array($locale, $this->dynamicLocales())) return null; |
|
117 | 117 | |
118 | 118 | return $value; |
119 | 119 | } |
@@ -113,7 +113,9 @@ |
||
113 | 113 | $value = $this->dynamic($key); |
114 | 114 | |
115 | 115 | // If value is localized, we wont return the entire value, but instead return null since no fallback will be provided. |
116 | - if(is_array($value) && in_array($locale, $this->dynamicLocales())) return null; |
|
116 | + if(is_array($value) && in_array($locale, $this->dynamicLocales())) { |
|
117 | + return null; |
|
118 | + } |
|
117 | 119 | |
118 | 120 | return $value; |
119 | 121 | } |
@@ -16,11 +16,11 @@ |
||
16 | 16 | |
17 | 17 | public static function fromRawValue($value): self |
18 | 18 | { |
19 | - if($value instanceof self) return $value; |
|
19 | + if ($value instanceof self) return $value; |
|
20 | 20 | |
21 | 21 | $value = is_null($value) ? [] : (is_array($value) ? $value : json_decode($value, true)); |
22 | 22 | |
23 | - return new static((array) $value); |
|
23 | + return new static((array)$value); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public function has(string $key): bool |
@@ -16,7 +16,9 @@ |
||
16 | 16 | |
17 | 17 | public static function fromRawValue($value): self |
18 | 18 | { |
19 | - if($value instanceof self) return $value; |
|
19 | + if($value instanceof self) { |
|
20 | + return $value; |
|
21 | + } |
|
20 | 22 | |
21 | 23 | $value = is_null($value) ? [] : (is_array($value) ? $value : json_decode($value, true)); |
22 | 24 |
@@ -21,16 +21,16 @@ |
||
21 | 21 | }, $payload); |
22 | 22 | |
23 | 23 | // remove all dead fragments |
24 | - $this->existingModel()->removeAllFragments($fragmentField->getKey(), array_map(function (Fragment $fragment) { |
|
24 | + $this->existingModel()->removeAllFragments($fragmentField->getKey(), array_map(function(Fragment $fragment) { |
|
25 | 25 | return $fragment->hasModelId() ? $fragment->getModelId() : null; |
26 | 26 | }, $fragments)); |
27 | 27 | |
28 | 28 | // Save each fragment |
29 | - foreach($fragments as $i => $fragment) { |
|
29 | + foreach ($fragments as $i => $fragment) { |
|
30 | 30 | $modelId = $this->existingModel()->saveFragment($fragment, $i); |
31 | 31 | |
32 | 32 | // Attach any asset |
33 | - if(isset($imagePayload[$i])) { |
|
33 | + if (isset($imagePayload[$i])) { |
|
34 | 34 | $fieldKey = key($imagePayload[$i]); |
35 | 35 | $imageField = $this->fields()->keyed($fragmentField->getKey())->first()->getFields()->keyed($fieldKey)->first(); |
36 | 36 |
@@ -23,8 +23,8 @@ |
||
23 | 23 | 'key' => $fragment->getKey(), 'order' => $order, |
24 | 24 | ], $fragment->getValues()); |
25 | 25 | |
26 | - if($fragment->hasModelId()){ |
|
27 | - $model =FragmentModel::find($fragment->getModelId()); |
|
26 | + if ($fragment->hasModelId()) { |
|
27 | + $model = FragmentModel::find($fragment->getModelId()); |
|
28 | 28 | $model->update($values); |
29 | 29 | |
30 | 30 | return $model->id; |
@@ -60,21 +60,21 @@ |
||
60 | 60 | ->setModelIdInputName($this->name.'[' . $k . '][modelId]') |
61 | 61 | ->setFields($this->fields->clone()->map(function(Field $field) use($k, $fragment){ |
62 | 62 | return $field->name($this->name.'.' . $k . '.' . $field->getName()) |
63 | - ->localizedFormat(':name.:locale') |
|
64 | - ->valueResolver(function($model = null, $locale = null, $field) use($fragment){ |
|
63 | + ->localizedFormat(':name.:locale') |
|
64 | + ->valueResolver(function($model = null, $locale = null, $field) use($fragment){ |
|
65 | 65 | |
66 | - if(isset($field->value)) return $field->value; |
|
66 | + if(isset($field->value)) return $field->value; |
|
67 | 67 | |
68 | - if($field instanceof MediaField){ |
|
69 | - if(!$fragment->hasModelId()){ |
|
70 | - return []; |
|
71 | - } |
|
68 | + if($field instanceof MediaField){ |
|
69 | + if(!$fragment->hasModelId()){ |
|
70 | + return []; |
|
71 | + } |
|
72 | 72 | |
73 | - return $field->getMedia(FragmentModel::find($fragment->getModelId()), $locale); |
|
74 | - } |
|
73 | + return $field->getMedia(FragmentModel::find($fragment->getModelId()), $locale); |
|
74 | + } |
|
75 | 75 | |
76 | - return $fragment->getValue($field->getColumn(), $locale); |
|
77 | - }); |
|
76 | + return $fragment->getValue($field->getColumn(), $locale); |
|
77 | + }); |
|
78 | 78 | })); |
79 | 79 | } |
80 | 80 |
@@ -42,31 +42,31 @@ discard block |
||
42 | 42 | $fragments = [Fragment::empty($this->getKey())]; |
43 | 43 | |
44 | 44 | // Model is auto-injected by Manager::editFields() method. |
45 | - if(($this->model)) { |
|
45 | + if (($this->model)) { |
|
46 | 46 | |
47 | - if(!method_exists($this->model, 'getFragments')) { |
|
48 | - throw new \RuntimeException(get_class($this->model) . ' is missing the ' . HasFragments::class . ' trait.'); |
|
47 | + if (!method_exists($this->model, 'getFragments')) { |
|
48 | + throw new \RuntimeException(get_class($this->model).' is missing the '.HasFragments::class.' trait.'); |
|
49 | 49 | } |
50 | 50 | |
51 | - if(count($modelFragments = $this->model->getFragments($this->getKey())) > 0) { |
|
52 | - $fragments = $modelFragments->map(function (FragmentModel $fragmentModel) { |
|
51 | + if (count($modelFragments = $this->model->getFragments($this->getKey())) > 0) { |
|
52 | + $fragments = $modelFragments->map(function(FragmentModel $fragmentModel) { |
|
53 | 53 | return Fragment::fromModel($fragmentModel); |
54 | 54 | })->all(); |
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | - foreach($fragments as $k => $fragment) { |
|
58 | + foreach ($fragments as $k => $fragment) { |
|
59 | 59 | $fragments[$k] = $fragments[$k] |
60 | - ->setModelIdInputName($this->name.'[' . $k . '][modelId]') |
|
60 | + ->setModelIdInputName($this->name.'['.$k.'][modelId]') |
|
61 | 61 | ->setFields($this->fields->clone()->map(function(Field $field) use($k, $fragment){ |
62 | - return $field->name($this->name.'.' . $k . '.' . $field->getName()) |
|
62 | + return $field->name($this->name.'.'.$k.'.'.$field->getName()) |
|
63 | 63 | ->localizedFormat(':name.:locale') |
64 | 64 | ->valueResolver(function($model = null, $locale = null, $field) use($fragment){ |
65 | 65 | |
66 | - if(isset($field->value)) return $field->value; |
|
66 | + if (isset($field->value)) return $field->value; |
|
67 | 67 | |
68 | - if($field instanceof MediaField){ |
|
69 | - if(!$fragment->hasModelId()){ |
|
68 | + if ($field instanceof MediaField) { |
|
69 | + if (!$fragment->hasModelId()) { |
|
70 | 70 | return []; |
71 | 71 | } |
72 | 72 | |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | |
84 | 84 | public function getDuplicatableFields(): array |
85 | 85 | { |
86 | - if(count($this->getFragments()) < 1) return []; |
|
86 | + if (count($this->getFragments()) < 1) return []; |
|
87 | 87 | |
88 | 88 | // Take the fields from the first fragment as a starting point for duplication |
89 | - return array_map(function(\Thinktomorrow\Chief\Fields\Types\Field $field){ |
|
90 | - return $field->valueResolver(function($model = null, $locale = null, $field){ |
|
91 | - if($field instanceof \Thinktomorrow\Chief\Fields\Types\MediaField) { return []; } |
|
89 | + return array_map(function(\Thinktomorrow\Chief\Fields\Types\Field $field) { |
|
90 | + return $field->valueResolver(function($model = null, $locale = null, $field) { |
|
91 | + if ($field instanceof \Thinktomorrow\Chief\Fields\Types\MediaField) { return []; } |
|
92 | 92 | return null; |
93 | 93 | })->render(); |
94 | 94 | }, $this->getFragments()[0]->getFields()->clone()->all()); |
@@ -63,7 +63,9 @@ discard block |
||
63 | 63 | ->localizedFormat(':name.:locale') |
64 | 64 | ->valueResolver(function($model = null, $locale = null, $field) use($fragment){ |
65 | 65 | |
66 | - if(isset($field->value)) return $field->value; |
|
66 | + if(isset($field->value)) { |
|
67 | + return $field->value; |
|
68 | + } |
|
67 | 69 | |
68 | 70 | if($field instanceof MediaField){ |
69 | 71 | if(!$fragment->hasModelId()){ |
@@ -83,7 +85,9 @@ discard block |
||
83 | 85 | |
84 | 86 | public function getDuplicatableFields(): array |
85 | 87 | { |
86 | - if(count($this->getFragments()) < 1) return []; |
|
88 | + if(count($this->getFragments()) < 1) { |
|
89 | + return []; |
|
90 | + } |
|
87 | 91 | |
88 | 92 | // Take the fields from the first fragment as a starting point for duplication |
89 | 93 | return array_map(function(\Thinktomorrow\Chief\Fields\Types\Field $field){ |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | public static function fromModel(FragmentModel $fragmentModel): self |
35 | 35 | { |
36 | - return new static($fragmentModel->key, $fragmentModel->values->all(), new Fields(), (int) $fragmentModel->id); |
|
36 | + return new static($fragmentModel->key, $fragmentModel->values->all(), new Fields(), (int)$fragmentModel->id); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | public static function fromNew(string $key, array $values): self |
@@ -48,14 +48,14 @@ discard block |
||
48 | 48 | |
49 | 49 | public static function fromRequestPayload(string $key, array $payload): self |
50 | 50 | { |
51 | - if(!isset($payload['modelId'])) { |
|
51 | + if (!isset($payload['modelId'])) { |
|
52 | 52 | return static::fromNew($key, $payload); |
53 | 53 | } |
54 | 54 | |
55 | 55 | $modelId = $payload['modelId']; |
56 | 56 | unset($payload['modelId']); |
57 | 57 | |
58 | - return new static($key, $payload, new Fields(), (int) $modelId); |
|
58 | + return new static($key, $payload, new Fields(), (int)$modelId); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | public function setFields(Fields $fields): self |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | |
73 | 73 | public function getValue(string $key, ?string $locale = null) |
74 | 74 | { |
75 | - if(!isset($this->values[$key])) { |
|
75 | + if (!isset($this->values[$key])) { |
|
76 | 76 | return null; |
77 | 77 | } |
78 | 78 | |
79 | 79 | // When the value is an array, it is assumed that this is an array of locales, each representing the value for that locale |
80 | - if(is_array($this->values[$key])) { |
|
81 | - if($locale && array_key_exists($locale, $this->values[$key])) { |
|
80 | + if (is_array($this->values[$key])) { |
|
81 | + if ($locale && array_key_exists($locale, $this->values[$key])) { |
|
82 | 82 | return $this->values[$key][$locale]; |
83 | 83 | } |
84 | 84 | } |