From df43102e64017c6282557ae8cfee95608070fe73 Mon Sep 17 00:00:00 2001 From: Chin Leung Date: Mon, 28 Oct 2019 16:06:35 -0400 Subject: [PATCH 1/9] Fixed the deletion of a file --- src/FieldCollection.php | 22 ++++++++++++++++++++++ src/TabsOnEdit.php | 12 +++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 src/FieldCollection.php diff --git a/src/FieldCollection.php b/src/FieldCollection.php new file mode 100644 index 0000000..35db2b7 --- /dev/null +++ b/src/FieldCollection.php @@ -0,0 +1,22 @@ +flatMap(function ($tab) use ($type) { + return collect(Arr::get($tab, 'fields'))->whereInstanceOf($type); + }); + } +} diff --git a/src/TabsOnEdit.php b/src/TabsOnEdit.php index 4bd591c..e879542 100644 --- a/src/TabsOnEdit.php +++ b/src/TabsOnEdit.php @@ -36,7 +36,8 @@ public function creationFields(NovaRequest $request) public static function fill(NovaRequest $request, $model) { return static::fillFields( - $request, $model, + $request, + $model, (new static($model))->parentCreationFields($request) ); } @@ -48,7 +49,8 @@ public static function fill(NovaRequest $request, $model) public static function fillForUpdate(NovaRequest $request, $model) { return static::fillFields( - $request, $model, + $request, + $model, (new static($model))->parentUpdateFields($request) ); } @@ -105,7 +107,7 @@ public static function rulesForUpdate(NovaRequest $request) */ public function updateFields(NovaRequest $request) { - return collect( + return new FieldCollection( [ 'Tabs' => [ 'component' => 'tabs', @@ -126,8 +128,8 @@ public function updateFields(NovaRequest $request) protected function assignToPanels($label, Collection $panels) { return $panels->map(function ($field) use ($label) { - if ( !is_array($field) && !$field->panel ) { - $field->panel = $label; + if (!is_array($field) && !$field->panel) { + $field->panel = $label; } return $field; From 7fd03f0bde1c86d8703415a0ea92259020fb957f Mon Sep 17 00:00:00 2001 From: Chin Leung Date: Wed, 13 Nov 2019 09:29:31 -0500 Subject: [PATCH 2/9] Updated method signature for Nova 2.7 --- src/TabsOnEdit.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/TabsOnEdit.php b/src/TabsOnEdit.php index e879542..11a162d 100644 --- a/src/TabsOnEdit.php +++ b/src/TabsOnEdit.php @@ -1,9 +1,9 @@ map(function ($field) use ($label) { if (!is_array($field) && !$field->panel) { From c33141afc9056b3c2efa7daf902d6cafce3ddd02 Mon Sep 17 00:00:00 2001 From: Chin Leung Date: Wed, 13 Nov 2019 10:34:24 -0500 Subject: [PATCH 3/9] Changed to return a FieldCollection for Nova 2.7 --- src/TabsOnEdit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TabsOnEdit.php b/src/TabsOnEdit.php index 11a162d..7a1cd58 100644 --- a/src/TabsOnEdit.php +++ b/src/TabsOnEdit.php @@ -11,11 +11,11 @@ trait TabsOnEdit * Resolve the creation fields. * * @param \Laravel\Nova\Http\Requests\NovaRequest $request - * @return \Illuminate\Support\Collection + * @return \Eminiarts\Tabs\FieldCollection */ public function creationFields(NovaRequest $request) { - return collect( + return new FieldCollection( [ 'Tabs' => [ 'component' => 'tabs', From ce22b3ccf980f4d182b4ab5f2c56d12bfa4f3c91 Mon Sep 17 00:00:00 2001 From: Chin Leung Date: Thu, 14 Nov 2019 08:43:48 -0500 Subject: [PATCH 4/9] Fixed duplicated namespace --- src/TabsOnEdit.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/TabsOnEdit.php b/src/TabsOnEdit.php index acd1bf4..aa589cf 100644 --- a/src/TabsOnEdit.php +++ b/src/TabsOnEdit.php @@ -4,7 +4,6 @@ use Laravel\Nova\Fields\FieldCollection as NovaFieldCollection; use Laravel\Nova\Panel; use Laravel\Nova\Http\Requests\NovaRequest; -use Laravel\Nova\Panel; trait TabsOnEdit { From 32c2f9efc05523a6db00820eb31ea318cf9d8691 Mon Sep 17 00:00:00 2001 From: Chin Leung Date: Thu, 14 Nov 2019 08:45:16 -0500 Subject: [PATCH 5/9] Fixed signature of assignToPanels --- src/TabsOnEdit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TabsOnEdit.php b/src/TabsOnEdit.php index aa589cf..144526c 100644 --- a/src/TabsOnEdit.php +++ b/src/TabsOnEdit.php @@ -125,7 +125,7 @@ public function updateFields(NovaRequest $request) * @param \Laravel\Nova\Fields\FieldCollection $panels * @return \Laravel\Nova\Fields\FieldCollection */ - protected function assignToPanels($label, FieldCollection $panels) + protected function assignToPanels($label, NovaFieldCollection $panels) { return $panels->map(function ($field) use ($label) { if (!is_array($field) && !$field->panel) { From 5a08ef75782057b55c68b6987bce101f2849a5c3 Mon Sep 17 00:00:00 2001 From: zippoxer Date: Mon, 25 Nov 2019 21:03:01 +0200 Subject: [PATCH 6/9] fixed findFieldByAttribute to look inside tabs fields --- src/FieldCollection.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/FieldCollection.php b/src/FieldCollection.php index 35db2b7..1afbcfb 100644 --- a/src/FieldCollection.php +++ b/src/FieldCollection.php @@ -19,4 +19,20 @@ public function whereInstanceOf($type) return collect(Arr::get($tab, 'fields'))->whereInstanceOf($type); }); } + + public function findFieldByAttribute($attribute, $default = null) + { + foreach ($this->items as $field) { + if (isset($field->attribute) && $field->attribute === $attribute) { + return $field; + } + + // Search the fields inside tabs. + if (is_array($field) && isset($field['component']) && $field['component'] === 'tabs') { + return static::make($field['fields'])->findFieldByAttribute($attribute, $default); + } + } + + return null; + } } From 4a3e62c33513bd55bf0938d918398e908bd5c163 Mon Sep 17 00:00:00 2001 From: Chin Leung Date: Tue, 17 Dec 2019 14:19:01 -0500 Subject: [PATCH 7/9] Update TabsOnEdit.php --- src/TabsOnEdit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TabsOnEdit.php b/src/TabsOnEdit.php index c180a85..bdcc995 100644 --- a/src/TabsOnEdit.php +++ b/src/TabsOnEdit.php @@ -17,7 +17,7 @@ trait TabsOnEdit */ public function creationFields(NovaRequest $request) { - return collect( + return new FieldCollection( [ 'Tabs' => [ 'component' => 'tabs', From 2e80628b53c7c4de7963595a29acc09a1a398e44 Mon Sep 17 00:00:00 2001 From: Chin Leung Date: Tue, 17 Dec 2019 14:20:37 -0500 Subject: [PATCH 8/9] Update TabsOnEdit.php --- src/TabsOnEdit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TabsOnEdit.php b/src/TabsOnEdit.php index bdcc995..17c31f2 100644 --- a/src/TabsOnEdit.php +++ b/src/TabsOnEdit.php @@ -21,7 +21,7 @@ public function creationFields(NovaRequest $request) [ 'Tabs' => [ 'component' => 'tabs', - 'fields' => $this->removeNonCreationFields($this->resolveFields($request)), + 'fields' => $this->removeNonCreationFields($request, $this->resolveFields($request)), 'panel' => Panel::defaultNameForCreate($request->newResource()), ], ] From f3c8a7430530662475b09fc2212e65634b0dd278 Mon Sep 17 00:00:00 2001 From: RVxLab <46111684+RVxLab@users.noreply.github.com> Date: Sun, 15 Nov 2020 14:28:39 +0100 Subject: [PATCH 9/9] Update TabsOnEdit.php --- src/TabsOnEdit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TabsOnEdit.php b/src/TabsOnEdit.php index 2c5a08e..8a0b12a 100644 --- a/src/TabsOnEdit.php +++ b/src/TabsOnEdit.php @@ -1,6 +1,6 @@