Skip to content

Commit

Permalink
Add ability to add to existing sections
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Dec 4, 2023
1 parent 896deeb commit 9d88f0a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Http/Controllers/CP/Forms/FormsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Statamic\Facades\Form;
use Statamic\Facades\User;
use Statamic\Http\Controllers\CP\CpController;
use Statamic\Support\Arr;
use Statamic\Support\Str;

class FormsController extends CpController
Expand Down Expand Up @@ -193,7 +194,7 @@ public function destroy($form)

protected function editFormBlueprint($form)
{
$fields = array_merge([
$fields = [
'name' => [
'display' => __('Name'),
'fields' => [
Expand Down Expand Up @@ -317,7 +318,21 @@ protected function editFormBlueprint($form)
// metrics
// ...

], Form::getConfigFor($form->handle()));
];

foreach (Form::getConfigFor($form->handle()) as $handle => $config) {
$merged = false;
foreach ($fields as $fieldHandle => $fieldConfig) {
if ($fieldConfig['display'] == $config['display']) {
$fields[$fieldHandle]['fields'] += $config['fields'];
$merged = true;
}
}

if (! $merged) {
$fields[] = $config;
}
}

return Blueprint::makeFromTabs($fields);
}
Expand Down

0 comments on commit 9d88f0a

Please sign in to comment.