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;
    }