Skip to content

Commit 046d126

Browse files
committed
fix form plugin
1 parent b727028 commit 046d126

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

src/FormsPlugin.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,36 @@ public function __construct(
5252
}
5353

5454
/**
55-
* @param string $formName
55+
* @param string $name
5656
* @return object
5757
*/
58-
public function __invoke(string $formName = null): object
58+
public function __invoke(string $name = null): object
5959
{
60-
if (is_null($formName)) {
60+
if (is_null($name)) {
6161
return $this;
6262
}
6363

64-
$form = null;
64+
$result = null;
6565
// check the container first, in case there is a form to get through the abstract factory
66-
$abstractFormName = FormAbstractServiceFactory::PREFIX . '.' . $formName;
66+
$abstractFormName = FormAbstractServiceFactory::PREFIX . '.' . $name;
6767
if ($this->container->has($abstractFormName)) {
68-
$form = $this->container->get($abstractFormName);
69-
} elseif ($this->formElementManager->has($formName)) {
70-
$form = $this->formElementManager->get($formName);
68+
$result = $this->container->get($abstractFormName);
69+
} elseif ($this->formElementManager->has($name)) {
70+
$result = $this->formElementManager->get($name);
7171
}
7272

73-
if (!$form) {
73+
if (!$result) {
7474
throw new RuntimeException(
75-
"Form with name $formName could not be created. Are you sure you registered it in the form manager?"
75+
"Form, fieldset or element with name $result could not be created. ' .
76+
'Are you sure you registered it in the form manager?"
7677
);
7778
}
7879

79-
$this->restoreFormState($form);
80-
return $form;
80+
if ($result instanceof Form) {
81+
$this->restoreFormState($result);
82+
}
83+
84+
return $result;
8185
}
8286

8387
/**

0 commit comments

Comments
 (0)