@php $homecontents = $homecontents ?? (isset($community) ? $community->present()->getHomeContents() : null); $pagesList = $pages ?? (isset($community) ? $community->present()->getPages() : collect()); $pagesList = is_array($pagesList) ? collect($pagesList) : $pagesList; $pagesList = ($pagesList instanceof \Illuminate\Support\Collection) ? $pagesList : collect($pagesList); $isIframePreview = $isIframePreview ?? false; $forceShowLoginInEditor = \Request::is('c/*/editpageheader/*'); $loginTitle = 'Sign In/up'; if (isset($homecontents) && $homecontents && !empty($homecontents->login_menu_title)) { $loginTitle = $homecontents->login_menu_title; } $menuItems = []; $menuItemIndex = 0; $pushMenuItem = function (int $srno, string $type, $payload = null) use (&$menuItems, &$menuItemIndex) { $menuItems[] = [ 'srno' => $srno, 'type' => $type, 'payload' => $payload, 'index' => $menuItemIndex++, ]; }; if (($homecontents && (int) ($homecontents->show_news_feed_menu ?? 0) === 1) || empty($homecontents)) { $pushMenuItem((int) ($homecontents->newsfeed_menu_srno ?? 0), 'news'); } if (($homecontents && (int) ($homecontents->show_event_menu ?? 0) === 1) || empty($homecontents)) { $pushMenuItem((int) ($homecontents->event_menu_srno ?? 0), 'events'); } if (isset($pagesList) && count($pagesList)) { foreach ($pagesList as $page) { $pushMenuItem((int) ($page->menu_srno ?? 0), 'page', $page); } } $shouldShowLoginMenu = ( $forceShowLoginInEditor || (($isIframePreview ?? false) && \Request::is('c/*/pagesheaders/default-header-preview')) || !\Auth::check() ) && (((isset($homecontents) && $homecontents && (int) ($homecontents->show_login_menu ?? 0) === 1)) || empty($homecontents)); if ($shouldShowLoginMenu) { $pushMenuItem((int) ($homecontents->login_menu_srno ?? 0), 'login'); } usort($menuItems, function ($a, $b) { $srnoA = (int) ($a['srno'] ?? 0); $srnoB = (int) ($b['srno'] ?? 0); if ($srnoA === $srnoB) { return ((int) $a['index']) <=> ((int) $b['index']); } return $srnoA <=> $srnoB; }); @endphp