Skip to content

Commit

Permalink
Added support to multiple config forms using
Browse files Browse the repository at this point in the history
  • Loading branch information
balajidharma committed Jul 28, 2024
1 parent d7425a6 commit 6a70cf8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/FormBuilderServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
8 changes: 4 additions & 4 deletions src/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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);
Expand Down

0 comments on commit 6a70cf8

Please sign in to comment.