protected function getMenuByName(string $name, $context = null): MenuInterface
    {
        // validate menu name
        $this->validateName($name);

        // get menu
        $menuEntity = null;
        try {
            $menuEntity = $this->Menus
                ->find('all')
                ->where(['name' => $name])
                ->firstOrFail();
            if (!($menuEntity instanceof EntityInterface)) {
                throw new RuntimeException(sprintf(
                    'Expected value of type "Cake\Datasource\EntityInterface", got "%s" instead',
                    gettype($menuEntity)
                ));
            }

            $menuInstance = $menuEntity->get('default') ?
                $this->getMenuItemsFromEvent($name, [], $context) :
                $this->getMenuItemsFromTable($menuEntity);
        } catch (RecordNotFoundException $e) {
            $menuInstance = static::getMenuItemsFromEvent($name, [], $context);
        }

        // maintain backwards compatibility for menu arrays
        if (is_array($menuInstance)) {
            $menuInstance = self::normaliseItems($menuInstance);
            if ($menuEntity instanceof EntityInterface && $menuEntity->get('default')) {
                $menuInstance = $this->sortItems($menuInstance);
            }

            $menuInstance = self::createMenu($menuInstance);
        }

        return $menuInstance;
    }
protected function getMenuByName(string $name, $context = null): MenuInterface
    {
        // validate menu name
        $this->validateName($name);

        // get menu
        $menuEntity = null;
        try {
            $menuEntity = $this->Menus
                ->find('all')
                ->where(['name' => $name])
                ->firstOrFail();
            if (!($menuEntity instanceof EntityInterface)) {
                throw new RuntimeException(sprintf(
                    'Expected value of type "Cake\Datasource\EntityInterface", got "%s" instead',
                    gettype($menuEntity)
                ));
            }

            $menuInstance = $menuEntity->get('default') ?
                $this->getMenuItemsFromEvent($name, [], $context) :
                $this->getMenuItemsFromTable($menuEntity);
        } catch (RecordNotFoundException $e) {
            $menuInstance = static::getMenuItemsFromEvent($name, [], $context);
        }

        // maintain backwards compatibility for menu arrays
        if (is_array($menuInstance)) {
            $menuInstance = self::normaliseItems($menuInstance);
            if ($menuEntity instanceof EntityInterface && $menuEntity->get('default')) {
                $menuInstance = $this->sortItems($menuInstance);
            }

            $menuInstance = self::createMenu($menuInstance);
        }

        return $menuInstance;
    }
protected function getMenuByName ( string $ name , $ context = null ) : MenuInterface { // validate menu name $ this -> validateName ( $ name ) ; // get menu $ menuEntity = null ; try { $ menuEntity = $ this -> Menus -> find ( 'all' ) -> where ( [ 'name' => $ name ] ) -> firstOrFail ( ) ; if ( ! ( $ menuEntity instanceof EntityInterface ) ) { throw new RuntimeException ( sprintf ( 'Expected value of type "Cake\Datasource\EntityInterface", got "%s" instead' , gettype ( $ menuEntity ) ) ) ; } $ menuInstance = $ menuEntity -> get ( 'default' ) ? $ this -> getMenuItemsFromEvent ( $ name , [ ] , $ context ) : $ this -> getMenuItemsFromTable ( $ menuEntity ) ; } catch ( RecordNotFoundException $ e ) { $ menuInstance = static :: getMenuItemsFromEvent ( $ name , [ ] , $ context ) ; } // maintain backwards compatibility for menu arrays if ( is_array ( $ menuInstance ) ) { $ menuInstance = self :: normaliseItems ( $ menuInstance ) ; if ( $ menuEntity instanceof EntityInterface && $ menuEntity -> get ( 'default' ) ) { $ menuInstance = $ this -> sortItems ( $ menuInstance ) ; } $ menuInstance = self :: createMenu ( $ menuInstance ) ; } return $ menuInstance ; }
Returns a menu instance based on the provided name

@param string $name Menu's name
@param null|mixed $context  The object that generates the menu to be used as the event subject
@return \Menu\MenuBuilder\MenuInterface
Returns a menu instance based on the provided name