From 6a70cf8f18a2410b70fc5c1b40ffa71fb4650b1b Mon Sep 17 00:00:00 2001 From: balajidharma Date: Sat, 27 Jul 2024 22:48:35 -0400 Subject: [PATCH] Added support to multiple config forms using --- src/Form.php | 10 +++++++++- src/FormBuilderServiceProvider.php | 2 +- src/FormHelper.php | 8 ++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Form.php b/src/Form.php index 9e03745..0437710 100644 --- a/src/Form.php +++ b/src/Form.php @@ -58,6 +58,14 @@ class Form */ protected $formConfig = []; + /** + * Form configuration name. + * + * @var array + */ + protected $formConfigName = null; + + /** * Additional data which can be used to build fields. * @@ -542,7 +550,7 @@ public function setFormOption($option, $value) */ public function getConfig($key = null, $default = null) { - return $this->formHelper->getConfig($key, $default, $this->formConfig); + return $this->formHelper->getConfig($key, $default, $this->formConfig, $this->formConfigName); } /** diff --git a/src/FormBuilderServiceProvider.php b/src/FormBuilderServiceProvider.php index de44712..79c0919 100644 --- a/src/FormBuilderServiceProvider.php +++ b/src/FormBuilderServiceProvider.php @@ -77,7 +77,7 @@ protected function registerFormHelper() $formHelperClass = $this->getFormHelperClass(); $this->app->singleton($abstract, function ($app) use ($formHelperClass) { - $configuration = $app->make(ConfigFactory::class)->formConfig(); + $configuration = $app->make(ConfigFactory::class); return new $formHelperClass($app['view'], $app['translator'], $configuration); }); diff --git a/src/FormHelper.php b/src/FormHelper.php index 0a366a3..71725f7 100644 --- a/src/FormHelper.php +++ b/src/FormHelper.php @@ -87,11 +87,11 @@ class FormHelper */ private $customTypes = []; - public function __construct(View $view, Translator $translator, array $config = []) + public function __construct(View $view, Translator $translator, ConfigFactory $configFactory) { $this->view = $view; $this->translator = $translator; - $this->config = $config; + $this->config = $configFactory; $this->loadCustomTypes(); } @@ -101,9 +101,9 @@ public function __construct(View $view, Translator $translator, array $config = * @param array $customConfig * @return mixed */ - public function getConfig($key = null, $default = null, $customConfig = []) + public function getConfig($key = null, $default = null, $customConfig = [], ?string $form = null) { - $config = array_replace_recursive($this->config, $customConfig); + $config = array_replace_recursive($this->config->formConfig($form), $customConfig); if ($key) { return Arr::get($config, $key, $default);