class Menu extends BaseMenu
{
/**
- * @var Item
+ * @var Item[}
*/
- protected static $_nav = null;
+ protected static $_nav = [];
protected const _STANDARD_PREFIX = 'cubist';
public const CACHE_TAG = 'cubist_nav';
$this->_registeredMenuMakers[$name] = $callback;
}
- public function get($key, $name = self::_STANDARD_PREFIX)
+ public function get($key, $name = self::_STANDARD_PREFIX, $locale = null)
{
+ if (null === $locale) {
+ $locale = App::getLocale();
+ }
if ($name) {
$key = $name . '_' . $key;
}
+ $key = $locale . '_' . $key;
if (!$this->exists($key)) {
- $this->makeAllMenus();
+ $this->makeAllMenus(App::getLocale());
}
return parent::get($key);
}
/**
* @return Item
*/
- public static function getNavigation()
+ public static function getNavigation($locale = null)
{
- if (self::$_nav === null) {
+ if (null === $locale) {
+ $locale = App::getLocale();
+ }
+ if (!isset(self::$_nav[$locale])) {
\Barryvdh\Debugbar\Facade::startMeasure('nav', 'Init Navigation object');
- self::$_nav = Cache::tags(self::CACHE_TAG)->remember('navigation_' . App::getLocale(), 43200, function () {
+ self::$_nav[$locale] = Cache::tags(self::CACHE_TAG)->remember('navigation_' . $locale, 43200, function () use ($locale) {
$nav = new Item();
+ $nav->setLocale($locale);
$nav->initFromDatabase();
return $nav;
});
\Barryvdh\Debugbar\Facade::stopMeasure('nav');
}
- return self::$_nav;
+ return self::$_nav[$locale];
}
}
$href = $page->getHref();
- if ($href == '#' || $href == 'home') {
+ if ($href === '#' || $href === 'home') {
continue;
}
- $url = action("PageController@catchall", ['page' => $href]);
+ $url = action('PageController@catchall', ['page' => $href]);
if (isset($res[$url])) {
continue;
}
public static function internalToHref($url)
{
- if (stristr($url, 'internal:')) {
+ if (stripos($url, 'internal:') !== false) {
$e = explode(':', $url, 2);
$url = $e[1];
}
return '#internalnotfound';
}
- public function makeAllMenus()
+ public function makeAllMenus($locale)
{
- $nav = self::getNavigation();
+ $nav = self::getNavigation($locale);
foreach ($nav->getChildren() as $main) {
- $this->makeStandardMenus($main);
+ $this->makeStandardMenus($main, $locale);
}
// Also make a menu for the breadcrumbs - this one is simpler and doesn't have the submenu headings
- $this->make(self::_STANDARD_PREFIX . '_breadcrumbs', function ($menu) use ($nav) {
+ $this->make($locale . '_' . self::_STANDARD_PREFIX . '_breadcrumbs', function ($menu) use ($nav) {
// Start with home link
$menu = $menu->add(__('Accueil'), '');
$this->_addToBreadcrumbs($nav, $menu);
});
}
- public function makeStandardMenus($item)
+ public function makeStandardMenus($item, $locale)
{
- $this->make(self::_STANDARD_PREFIX . '_' . $item->getName(), function ($menu) use ($item) {
+ $this->make($locale . '_' . self::_STANDARD_PREFIX . '_' . $item->getName(), function ($menu) use ($item) {
$this->makeStandardMenu($menu, $item);
});
- $this->make('mobile_' . $item->getName(), function ($menu) use ($item) {
+ $this->make($locale . '_' . 'mobile_' . $item->getName(), function ($menu) use ($item) {
$this->makeMobileMenu($menu, $item);
});
foreach ($this->_registeredMenuMakers as $name => $registeredMenuMaker) {
- $this->make($name . '_' . $item->getName(), function ($menu) use ($item, $registeredMenuMaker) {
- call_user_func($registeredMenuMaker, $menu, $item);
+ $this->make($locale . '_' . $name . '_' . $item->getName(), function ($menu) use ($item, $registeredMenuMaker) {
+ $registeredMenuMaker($menu, $item);
});
}
}
protected function _addToBreadcrumbs($nav, $menu)
{
if ($nav->getTitle() && $nav->isBreadcrumbs()) {
- if (substr($nav->getBreadcrumbHref(), 0, 1) == '#') {
+ if (strpos($nav->getBreadcrumbHref(), '#') === 0) {
$parent = $menu->raw($nav->getTitle());
} else {
$parent = $menu->add($nav->getTitle(), $nav->getBreadcrumbHref());
public function getSearchBreadcrumbs()
{
$all = $this->get('breadcrumbs')->crumbMenu()->all();
- $lastIndex = count($all )-1;
- $search_breadcrumbs=[];
+ $lastIndex = count($all) - 1;
+ $search_breadcrumbs = [];
foreach ($all as $i => $item) {
if ($i === 0 || $i === $lastIndex) {
continue;
*/
public function initFromEntity($entity)
{
- $data=$entity->getPageData();
+ if (method_exists($entity, 'setLocale')) {
+ $entity->setLocale($this->getLocale());
+ }
+ $data = $entity->getPageData();
- $this->setId($entity->id);
- $this->setName($entity->name ?? get_class($entity) . '_' . $entity->id);
- $this->setSlug($entity->slug);
- $this->setTitle($entity->title);
- $this->setRobots($data->get('robots',true));
+ $this->setId($data->get('id'));
+ $this->setName($data->get('name', get_class($entity) . '_' . $data->get('id')));
+ $this->setSlug($data->get('slug'));
+ $this->setTitle($data->get('title'));
+ $this->setRobots($data->get('robots', true));
$desktop = $entity->menu_desktop == '' ? 'children' : $entity->menu_desktop;
- $this->setMenuDesktop($entity->menu_desktop != 'no');
- $this->setMenuDesktopChildren($entity->menu_desktop == 'children');
+ $this->setMenuDesktop($entity->menu_desktop !== 'no');
+ $this->setMenuDesktopChildren($entity->menu_desktop === 'children');
- $mobile = $entity->menu_mobile == 'desktop' || $entity->menu_mobile == '' ? $desktop : $entity->menu_mobile;
+ $mobile = $entity->menu_mobile === 'desktop' || $entity->menu_mobile == '' ? $desktop : $entity->menu_mobile;
- $this->setMenuMobile($mobile != 'no');
- $this->setMenuMobileChildren($mobile == 'children');
+ $this->setMenuMobile($mobile !== 'no');
+ $this->setMenuMobileChildren($mobile === 'children');
- $dbaliases = $entity->getPageData()->url_alias;
+ $dbaliases = $data->get('url_alias');
if (is_array($dbaliases)) {
$aliases = [];
foreach ($dbaliases as $dbalias) {
if (!$template) {
return true;
}
- if ($template == 'first_redirection' || $template == 'internal_redirection' || $template == 'redirection' || $this->isVirtual()) {
+ if ($template === 'first_redirection' || $template === 'internal_redirection' || $template === 'redirection' || $this->isVirtual()) {
return false;
}
return parent::isNavigable();
return parent::getHref();
}
- if ($template == 'first_redirection' && $this->hasChildren()) {
+ if ($template === 'first_redirection' && $this->hasChildren()) {
return $this->getChildren()[0]->getHref();
- } else if ($template == 'internal_redirection') {
+ } else if ($template === 'internal_redirection') {
- } else if ($template == 'redirection') {
+ } else if ($template === 'redirection') {
return $this->navigation;
}
public function getBreadcrumbHref()
{
- if ($this->getTemplate() == 'first_redirection' && $this->hasChildren()) {
+ if ($this->getTemplate() === 'first_redirection' && $this->hasChildren()) {
return '#';
- } else if ($this->getTemplate() == 'internal_redirection') {
+ } else if ($this->getTemplate() === 'internal_redirection') {
return '#';
- } else if ($this->getTemplate() == 'redirection') {
+ } else if ($this->getTemplate() === 'redirection') {
return '#';
} else if ($this->isVirtual()) {
return '#';