1414use Laminas \Form \Element \Select ;
1515use Laminas \Form \Element \Submit ;
1616use Laminas \Form \Element \Text ;
17+ use Laminas \Form \Exception \ExceptionInterface ;
1718use Laminas \Form \Fieldset ;
1819use Laminas \Session \Container ;
1920
@@ -26,6 +27,7 @@ class CreateUserForm extends AbstractForm
2627{
2728 /**
2829 * @param array<non-empty-string, mixed> $options
30+ * @throws ExceptionInterface
2931 */
3032 public function __construct (?string $ name = null , array $ options = [])
3133 {
@@ -43,16 +45,20 @@ public function __construct(?string $name = null, array $options = [])
4345
4446 /**
4547 * @phpstan-param SelectDataType[] $roles
48+ * @throws ExceptionInterface
4649 */
47- public function setRoles (array $ roles ): self
50+ public function setRoles (array $ roles ): static
4851 {
49- return $ this -> add (
50- ( new MultiCheckbox ( ' roles ' ))
51- -> setLabel ( ' Select at least one role ' )
52- -> setValueOptions ( $ roles )
53- ) ;
52+ $ checkbox = new MultiCheckbox ( ' roles ' );
53+ $ checkbox -> setLabel ( ' Select at least one role ' );
54+ $ checkbox -> setValueOptions ( $ roles );
55+ $ this -> add ( $ checkbox );
56+ return $ this ;
5457 }
5558
59+ /**
60+ * @throws ExceptionInterface
61+ */
5662 public function init (): void
5763 {
5864 $ this
@@ -68,11 +74,6 @@ public function init(): void
6874 (new Password ('passwordConfirm ' ))
6975 ->setLabel ('Password confirm ' )
7076 ->setAttribute ('required ' , true )
71- )->add (
72- (new Select ('status ' ))
73- ->setLabel ('Account status ' )
74- ->setValueOptions (UserStatusEnum::toArray ())
75- ->setAttribute ('required ' , true )
7677 )->add (
7778 (new Csrf ('userCreateCsrf ' ))
7879 ->setOptions ([
@@ -100,5 +101,11 @@ public function init(): void
100101 ->setAttribute ('required ' , true )
101102 )
102103 );
104+
105+ $ select = new Select ('status ' );
106+ $ select ->setLabel ('Account status ' );
107+ $ select ->setValueOptions (UserStatusEnum::toArray ());
108+ $ select ->setAttribute ('required ' , true );
109+ $ this ->add ($ select );
103110 }
104111}
0 commit comments