@@ -59,10 +59,10 @@ public function addLineBreak(string $breakChar = ' ', int $lines = 1) : self
59
59
}
60
60
61
61
/**
62
- * Add a submenu with a name . The name will be displayed as the item text
62
+ * Add a submenu with a unique ID and the text . The text will be displayed as the item text
63
63
* in the parent menu.
64
64
*/
65
- public function addSubMenu (string $ id , string $ text, CliMenuBuilder $ subMenuBuilder = null ) : Builder
65
+ public function addSubMenu (string $ id , string $ text ) : CliMenuBuilder
66
66
{
67
67
if (isset ($ this ->subMenuBuilders [$ id ])) {
68
68
throw new \InvalidArgumentException (
@@ -76,11 +76,28 @@ public function addSubMenu(string $id, string $text, CliMenuBuilder $subMenuBuil
76
76
'id ' => $ id
77
77
];
78
78
79
- if (null === $ subMenuBuilder ) {
80
- $ this ->subMenuBuilders [$ id ] = new CliMenuBuilder ($ this );
81
- return $ this ->subMenuBuilders [$ id ];
79
+ $ this ->subMenuBuilders [$ id ] = new CliMenuBuilder ($ this );
80
+ return $ this ->subMenuBuilders [$ id ];
81
+ }
82
+
83
+ /**
84
+ * Add a submenu from an existing builder. Required a unique ID and the text. The text will be displayed as the
85
+ * item text in the parent menu.
86
+ */
87
+ public function addSubMenuFromExistingBuilder (string $ id , string $ text , CliMenuBuilder $ subMenuBuilder ) : self
88
+ {
89
+ if (isset ($ this ->subMenuBuilders [$ id ])) {
90
+ throw new \InvalidArgumentException (
91
+ sprintf ('SubMenu with id: "%s" already exists. $id must be unique ' , $ id )
92
+ );
82
93
}
83
94
95
+ $ this ->menuItems [] = [
96
+ 'type ' => 'submenu-placeholder ' ,
97
+ 'text ' => $ text ,
98
+ 'id ' => $ id
99
+ ];
100
+
84
101
$ this ->subMenuBuilders [$ id ] = $ subMenuBuilder ;
85
102
return $ this ;
86
103
}
0 commit comments