XE 3 (xpressengine 3) - instance 와 관련된 헬퍼 함수

- current_instance_id

if (!function_exists('current_instance_id')) {
    /**
     * Return current Instance Id
     *
     * @package Xpressengine\\Menu
     *
     * @return string
     */
    function current_instance_id()
    {
        $instanceConfig = Xpressengine\\Routing\\InstanceConfig::instance();
        return $instanceConfig->getInstanceId();
    }
}

- current_menu

/**
 * Returns current menu item
 *
 * @package Xpressengine\\Menu
 * @return Xpressengine\\Menu\\Models\\MenuItem|null
 */
function current_menu()
{
    $instanceConfig = Xpressengine\\Routing\\InstanceConfig::instance();
    return $instanceConfig->getMenuItem();
}

- menu_list

/**
     * 메뉴를 html 마크업으로 출력할 때, 사용하기 쉽도록 메뉴아이템 리스트를 제공한다.
     *
     * @package Xpressengine\\Menu
     *
     * @param string               $menuId   출력할 메뉴의 ID
     * @param string|callable|null $selected 선택된 아이템 지정
     *
     * @return Illuminate\\Support\\Collection 메뉴아이템 리스트
     */
    function menu_list($menuId, $selected = null)
    {
        $menu = null;
        if ($menuId !== null) {
            $menu = XeMenu::menus()->findWith(
                $menuId,
                [
                    'items.basicImage',
                    'items.hoverImage',
                    'items.selectedImage',
                    'items.mBasicImage',
                    'items.mHoverImage',
                    'items.mSelectedImage'
                ]
            );
        }

        /** @var Xpressengine\\Menu\\Models\\Menu $menu */
        if ($menu !== null) {
            if (!function_exists('removeInvisible')) {

                /**
                 * 보이지 않는(보기 권한이 없는) 메뉴는 제외시킨다.
                 *
                 * @param \\Xpressengine\\Menu\\Models\\MenuItem $item menu item
                 * @param \\Xpressengine\\Menu\\Models\\Menu     $menu menu
                 *
                 * @return null|\\Xpressengine\\Menu\\Models\\MenuItem
                 */
                function removeInvisible($item, $menu)
                {

                    // resolve item
                    if (Gate::denies('visible', [$item, $menu])) {
                        return null;
                    }

                    // resolve child menuitems of item
                    $children = new \\Illuminate\\Support\\Collection();
                    foreach ($item->getChildren() as $child) {
                        if ($new = removeInvisible($child, $menu)) {
                            if ($new) {
                                $children[] = $new;
                            }
                        }
                    }
                    $item->setChildren($children);

                    return $item;
                }
            }

            $current = $selected ?: current_instance_id();
            if ($current !== null) {
                $menu->setItemSelected($current);
            }
            $tree = $menu->getTree()->getTreeNodes();

            // resolve menu visible
            $menuTree = [];
            foreach ($tree as $item) {
                if ($new = removeInvisible($item, $menu)) {
                    $menuTree[] = $new;
                }
            }

            return $menuTree;
        } else {
            return new Illuminate\\Support\\Collection();
        }
    }
  • share