@@ -74,6 +74,11 @@ class CliMenuBuilder
7474 */
7575 private $ disableDefaultItems = false ;
7676
77+ /**
78+ * @var bool
79+ */
80+ private $ disabled ;
81+
7782 /**
7883 * @param CliMenuBuilder|null $parent
7984 */
@@ -130,13 +135,14 @@ public function addMenuItem(MenuItemInterface $item)
130135 * @param string $text
131136 * @param callable $itemCallable
132137 * @param bool $showItemExtra
138+ * @param bool $disabled
133139 * @return $this
134140 */
135- public function addItem ($ text , callable $ itemCallable , $ showItemExtra = false )
141+ public function addItem ($ text , callable $ itemCallable , $ showItemExtra = false , $ disabled = false )
136142 {
137143 Assertion::string ($ text );
138144
139- $ this ->addMenuItem (new SelectableItem ($ text , $ itemCallable , $ showItemExtra ));
145+ $ this ->addMenuItem (new SelectableItem ($ text , $ itemCallable , $ showItemExtra, $ disabled ));
140146
141147 return $ this ;
142148 }
@@ -211,6 +217,32 @@ public function addSubMenu($id)
211217 return $ this ->subMenus [$ id ];
212218 }
213219
220+ /**
221+ * Disable a submenu
222+ * @throws \InvalidArgumentException
223+ * @return $this
224+ */
225+ public function disableMenu ()
226+ {
227+ if (!$ this ->parent ) {
228+ throw new \InvalidArgumentException (
229+ 'You can \'t disable the root menu '
230+ );
231+ }
232+
233+ $ this ->disabled = true ;
234+
235+ return $ this ;
236+ }
237+
238+ /**
239+ * @return bool
240+ */
241+ public function isMenuDisabled ()
242+ {
243+ return $ this ->disabled ;
244+ }
245+
214246 /**
215247 * @param string $goBackButtonTest
216248 * @return $this
@@ -462,7 +494,7 @@ private function buildSubMenus(array $items)
462494 $ menuBuilder = $ this ->subMenus [$ item ];
463495 $ this ->subMenus [$ item ] = $ menuBuilder ->build ();
464496
465- return new MenuMenuItem ($ item , $ this ->subMenus [$ item ]);
497+ return new MenuMenuItem ($ item , $ this ->subMenus [$ item ], $ menuBuilder -> isMenuDisabled () );
466498 }, $ items );
467499 }
468500
0 commit comments