@@ -8,7 +8,7 @@  | 
                                                    ||
| 8 | 8 | |
| 9 | 9 | public function tagged($tag): bool  | 
                                                        
| 10 | 10 |      { | 
                                                        
| 11 | - $tags = (array) $tag;  | 
                                                        |
| 11 | + $tags = (array)$tag;  | 
                                                        |
| 12 | 12 | |
| 13 | 13 | return count(array_intersect($this->tags, $tags)) > 0;  | 
                                                        
| 14 | 14 | }  | 
                                                        
@@ -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 | }  | 
                                                        
@@ -88,7 +88,7 @@ discard block  | 
                                                    ||
| 88 | 88 | $this->pageBuilderField(),  | 
                                                        
| 89 | 89 |              InputField::make('title')->translatable($this->model->availableLocales()) | 
                                                        
| 90 | 90 |                  ->validation('required-fallback-locale|max:200', [], [ | 
                                                        
| 91 | -                    'trans.' . config('app.fallback_locale', 'nl') . '.title' => 'title', | 
                                                        |
| 91 | +                    'trans.'.config('app.fallback_locale', 'nl').'.title' => 'title', | 
                                                        |
| 92 | 92 | ])  | 
                                                        
| 93 | 93 |                  ->label('Intern label') | 
                                                        
| 94 | 94 |                  ->description('Dit is de benaming die zal worden getoond in de admin selectie velden.') | 
                                                        
@@ -210,7 +210,7 @@ discard block  | 
                                                    ||
| 210 | 210 |              if (is_array_empty($translation)) { | 
                                                        
| 211 | 211 | |
| 212 | 212 | // Nullify all values  | 
                                                        
| 213 | -                $trans[$locale] = array_map(function ($value) { | 
                                                        |
| 213 | +                $trans[$locale] = array_map(function($value) { | 
                                                        |
| 214 | 214 | return null;  | 
                                                        
| 215 | 215 | }, $translation);  | 
                                                        
| 216 | 216 | continue;  | 
                                                        
@@ -36,7 +36,7 @@ discard block  | 
                                                    ||
| 36 | 36 | |
| 37 | 37 | public function onlyModules(): Collection  | 
                                                        
| 38 | 38 |      { | 
                                                        
| 39 | -        return $this->collection()->reject(function ($item) { | 
                                                        |
| 39 | +        return $this->collection()->reject(function($item) { | 
                                                        |
| 40 | 40 |              if ($item instanceof Page || $item instanceof StoredSetReference) { | 
                                                        
| 41 | 41 | return true;  | 
                                                        
| 42 | 42 | }  | 
                                                        
@@ -45,7 +45,7 @@ discard block  | 
                                                    ||
| 45 | 45 | |
| 46 | 46 | public function onlyPages(): Collection  | 
                                                        
| 47 | 47 |      { | 
                                                        
| 48 | -        return $this->collection()->filter(function ($item) { | 
                                                        |
| 48 | +        return $this->collection()->filter(function($item) { | 
                                                        |
| 49 | 49 |              if ($item instanceof Page) { | 
                                                        
| 50 | 50 | return true;  | 
                                                        
| 51 | 51 | }  | 
                                                        
@@ -75,12 +75,12 @@ discard block  | 
                                                    ||
| 75 | 75 | |
| 76 | 76 | // Merging the results of all the pages and all the modules, then filter by the config  | 
                                                        
| 77 | 77 | // This prevents us from having duplicates and also reduces the query load.  | 
                                                        
| 78 | -        $collection = $collection->filter(function ($page) use ($available_children_types) { | 
                                                        |
| 78 | +        $collection = $collection->filter(function($page) use ($available_children_types) { | 
                                                        |
| 79 | 79 | return in_array(get_class($page), $available_children_types);  | 
                                                        
| 80 | 80 | });  | 
                                                        
| 81 | 81 | |
| 82 | 82 | // Filter out our already loaded pages and modules  | 
                                                        
| 83 | -        $remaining_children_types = collect($available_children_types)->reject(function ($type) { | 
                                                        |
| 83 | +        $remaining_children_types = collect($available_children_types)->reject(function($type) { | 
                                                        |
| 84 | 84 | return (new $type() instanceof Page || new $type() instanceof Module);  | 
                                                        
| 85 | 85 | });  | 
                                                        
| 86 | 86 | |
@@ -92,12 +92,12 @@ discard block  | 
                                                    ||
| 92 | 92 | }  | 
                                                        
| 93 | 93 | |
| 94 | 94 | // Remove duplicate models  | 
                                                        
| 95 | -        $collection = $collection->unique(function ($model) { | 
                                                        |
| 95 | +        $collection = $collection->unique(function($model) { | 
                                                        |
| 96 | 96 | return (new FlatReference(get_class($model), $model->id))->get();  | 
                                                        
| 97 | 97 | });  | 
                                                        
| 98 | 98 | |
| 99 | 99 | // Filter out our parent  | 
                                                        
| 100 | -        return $this->collection = $collection->reject(function ($item) { | 
                                                        |
| 100 | +        return $this->collection = $collection->reject(function($item) { | 
                                                        |
| 101 | 101 |              if ($item instanceof $this->parent) { | 
                                                        
| 102 | 102 | return $item->id == $this->parent->id;  | 
                                                        
| 103 | 103 | }  | 
                                                        
@@ -51,8 +51,8 @@  | 
                                                    ||
| 51 | 51 | |
| 52 | 52 | public function editFields(): Fields  | 
                                                        
| 53 | 53 |      { | 
                                                        
| 54 | -        return $this->fields()->map(function (Field $field) { | 
                                                        |
| 55 | -            return $field->valueResolver(function ($model = null, $locale = null, $field) { | 
                                                        |
| 54 | +        return $this->fields()->map(function(Field $field) { | 
                                                        |
| 55 | +            return $field->valueResolver(function($model = null, $locale = null, $field) { | 
                                                        |
| 56 | 56 | return $this->settings->get($field->getKey(), $locale);  | 
                                                        
| 57 | 57 | });  | 
                                                        
| 58 | 58 | });  | 
                                                        
@@ -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;  | 
                                                        
@@ -63,22 +63,22 @@  | 
                                                    ||
| 63 | 63 | ->setModelIdInputName($this->name . '[' . $k . '][modelId]')  | 
                                                        
| 64 | 64 |                  ->setFields($this->fields->clone()->map(function (Field $field) use ($k, $fragment) { | 
                                                        
| 65 | 65 | return $field->name($this->name . '.' . $k . '.' . $field->getName())  | 
                                                        
| 66 | -                                 ->localizedFormat(':name.:locale') | 
                                                        |
| 67 | -                                 ->valueResolver(function ($model = null, $locale = null, $field) use ($fragment) { | 
                                                        |
| 68 | -                                     if (isset($field->value)) { | 
                                                        |
| 69 | - return $field->value;  | 
                                                        |
| 70 | - }  | 
                                                        |
| 71 | -  | 
                                                        |
| 72 | -                                     if ($field instanceof MediaField) { | 
                                                        |
| 73 | -                                         if (!$fragment->hasModelId()) { | 
                                                        |
| 74 | - return [];  | 
                                                        |
| 75 | - }  | 
                                                        |
| 76 | -  | 
                                                        |
| 77 | - return $field->getMedia(FragmentModel::find($fragment->getModelId()), $locale);  | 
                                                        |
| 78 | - }  | 
                                                        |
| 79 | -  | 
                                                        |
| 80 | - return $fragment->getValue($field->getColumn(), $locale);  | 
                                                        |
| 81 | - });  | 
                                                        |
| 66 | +                                    ->localizedFormat(':name.:locale') | 
                                                        |
| 67 | +                                    ->valueResolver(function ($model = null, $locale = null, $field) use ($fragment) { | 
                                                        |
| 68 | +                                        if (isset($field->value)) { | 
                                                        |
| 69 | + return $field->value;  | 
                                                        |
| 70 | + }  | 
                                                        |
| 71 | +  | 
                                                        |
| 72 | +                                        if ($field instanceof MediaField) { | 
                                                        |
| 73 | +                                            if (!$fragment->hasModelId()) { | 
                                                        |
| 74 | + return [];  | 
                                                        |
| 75 | + }  | 
                                                        |
| 76 | +  | 
                                                        |
| 77 | + return $field->getMedia(FragmentModel::find($fragment->getModelId()), $locale);  | 
                                                        |
| 78 | + }  | 
                                                        |
| 79 | +  | 
                                                        |
| 80 | + return $fragment->getValue($field->getColumn(), $locale);  | 
                                                        |
| 81 | + });  | 
                                                        |
| 82 | 82 | }));  | 
                                                        
| 83 | 83 | }  | 
                                                        
| 84 | 84 | |
@@ -48,11 +48,11 @@ discard block  | 
                                                    ||
| 48 | 48 | // Model is auto-injected by Manager::editFields() method.  | 
                                                        
| 49 | 49 |          if (($this->model)) { | 
                                                        
| 50 | 50 |              if (!method_exists($this->model, 'getFragments')) { | 
                                                        
| 51 | - throw new \RuntimeException(get_class($this->model) . ' is missing the ' . HasFragments::class . ' trait.');  | 
                                                        |
| 51 | + throw new \RuntimeException(get_class($this->model).' is missing the '.HasFragments::class.' trait.');  | 
                                                        |
| 52 | 52 | }  | 
                                                        
| 53 | 53 | |
| 54 | 54 |              if (count($modelFragments = $this->model->getFragments($this->getKey())) > 0) { | 
                                                        
| 55 | -                $fragments = $modelFragments->map(function (FragmentModel $fragmentModel) { | 
                                                        |
| 55 | +                $fragments = $modelFragments->map(function(FragmentModel $fragmentModel) { | 
                                                        |
| 56 | 56 | return Fragment::fromModel($fragmentModel);  | 
                                                        
| 57 | 57 | })->all();  | 
                                                        
| 58 | 58 | }  | 
                                                        
@@ -60,11 +60,11 @@ discard block  | 
                                                    ||
| 60 | 60 | |
| 61 | 61 |          foreach ($fragments as $k => $fragment) { | 
                                                        
| 62 | 62 | $fragments[$k] = $fragments[$k]  | 
                                                        
| 63 | - ->setModelIdInputName($this->name . '[' . $k . '][modelId]')  | 
                                                        |
| 64 | -                ->setFields($this->fields->clone()->map(function (Field $field) use ($k, $fragment) { | 
                                                        |
| 65 | - return $field->name($this->name . '.' . $k . '.' . $field->getName())  | 
                                                        |
| 63 | + ->setModelIdInputName($this->name.'['.$k.'][modelId]')  | 
                                                        |
| 64 | +                ->setFields($this->fields->clone()->map(function(Field $field) use ($k, $fragment) { | 
                                                        |
| 65 | + return $field->name($this->name.'.'.$k.'.'.$field->getName())  | 
                                                        |
| 66 | 66 |                                   ->localizedFormat(':name.:locale') | 
                                                        
| 67 | -                                 ->valueResolver(function ($model = null, $locale = null, $field) use ($fragment) { | 
                                                        |
| 67 | +                                 ->valueResolver(function($model = null, $locale = null, $field) use ($fragment) { | 
                                                        |
| 68 | 68 |                                       if (isset($field->value)) { | 
                                                        
| 69 | 69 | return $field->value;  | 
                                                        
| 70 | 70 | }  | 
                                                        
@@ -110,8 +110,8 @@ discard block  | 
                                                    ||
| 110 | 110 | }  | 
                                                        
| 111 | 111 | |
| 112 | 112 | // Take the fields from the first fragment as a starting point for duplication  | 
                                                        
| 113 | -        return array_map(function (\Thinktomorrow\Chief\Fields\Types\Field $field) { | 
                                                        |
| 114 | -            return $field->valueResolver(function ($model = null, $locale = null, $field) { | 
                                                        |
| 113 | +        return array_map(function(\Thinktomorrow\Chief\Fields\Types\Field $field) { | 
                                                        |
| 114 | +            return $field->valueResolver(function($model = null, $locale = null, $field) { | 
                                                        |
| 115 | 115 |                  if ($field instanceof \Thinktomorrow\Chief\Fields\Types\MediaField) { | 
                                                        
| 116 | 116 | return [];  | 
                                                        
| 117 | 117 | }  | 
                                                        
@@ -34,7 +34,7 @@ discard block  | 
                                                    ||
| 34 | 34 | |
| 35 | 35 | public static function fromModel(FragmentModel $fragmentModel): self  | 
                                                        
| 36 | 36 |      { | 
                                                        
| 37 | - return new static($fragmentModel->key, $fragmentModel->values->all(), new Fields(), (int) $fragmentModel->id);  | 
                                                        |
| 37 | + return new static($fragmentModel->key, $fragmentModel->values->all(), new Fields(), (int)$fragmentModel->id);  | 
                                                        |
| 38 | 38 | }  | 
                                                        
| 39 | 39 | |
| 40 | 40 | public static function fromNew(string $key, array $values): self  | 
                                                        
@@ -56,7 +56,7 @@ discard block  | 
                                                    ||
| 56 | 56 | $modelId = $payload['modelId'];  | 
                                                        
| 57 | 57 | unset($payload['modelId']);  | 
                                                        
| 58 | 58 | |
| 59 | - return new static($key, $payload, new Fields(), (int) $modelId);  | 
                                                        |
| 59 | + return new static($key, $payload, new Fields(), (int)$modelId);  | 
                                                        |
| 60 | 60 | }  | 
                                                        
| 61 | 61 | |
| 62 | 62 | public function setFields(Fields $fields): self  | 
                                                        
@@ -13,15 +13,15 @@  | 
                                                    ||
| 13 | 13 | public function saveFragmentFields(FragmentField $fragmentField, Request $request)  | 
                                                        
| 14 | 14 |      { | 
                                                        
| 15 | 15 | $payload = $request->input($fragmentField->getDottedName(), []);  | 
                                                        
| 16 | -        $imagePayload = $request->input('images.' . $fragmentField->getDottedName(), []); | 
                                                        |
| 16 | +        $imagePayload = $request->input('images.'.$fragmentField->getDottedName(), []); | 
                                                        |
| 17 | 17 | |
| 18 | 18 | // Compose Fragment instances for each payload entry  | 
                                                        
| 19 | -        $fragments = array_map(function ($fragmentPayload) use ($fragmentField) { | 
                                                        |
| 19 | +        $fragments = array_map(function($fragmentPayload) use ($fragmentField) { | 
                                                        |
| 20 | 20 | return Fragment::fromRequestPayload($fragmentField->getKey(), $fragmentPayload); // (new Fragment($field->getKey(), $fragmentPayload));  | 
                                                        
| 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 | |