namespace Cubist\Backpack\app\Http\Controllers;
+use Cubist\Backpack\app\Magic\Menu\Facade as CubistMenu;
use Cubist\Backpack\app\Magic\Menu\Menu;
use Cubist\Backpack\app\Magic\Models\CMSPage;
use Illuminate\Http\Request;
$this->_404();
}
$c = $item->getController();
+ CubistMenu::setCurrentPage($item);
// Make Request object available as first parameter
$c['params'] = ['request' => $request] + $c['params'];
namespace Cubist\Backpack\app\Magic\Menu;
use Cubist\Backpack\app\Magic\Models\CMSPage;
+use Cubist\Backpack\app\Magic\Models\Locale;
use Cubist\Backpack\app\Template\Navigation;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Str;
$this->_href = $href;
}
+ public function getURL()
+ {
+ $domain = Locale::getMainDomain($this->getLocale());
+ $href = $this->getHref();
+ if ($href === 'home') {
+ $href = '';
+ }
+ if (!$domain) {
+ return $href;
+ }
+ return 'https://' . $domain . $href;
+ }
+
public function isNavigable()
{
return $this->_href != '#';
return $this->_robots;
}
+ public function getTranslatedPage($locale)
+ {
+ if ($this->getLocale() === $locale) {
+ return $this;
+ }
+ $res = Menu::getNavigation($locale)->findOneById($this->getId());
+ return $res;
+ }
+
/**
* @return string
*/
protected $_registeredMenuMakers = [];
+ /**
+ * @var Item
+ */
+ protected $_currentPage;
+
public function registerMenuMaker($name, $callback)
{
$this->_registeredMenuMakers[$name] = $callback;
}
+
public function get($key, $name = self::_STANDARD_PREFIX, $locale = null)
{
if (null === $locale) {
$res .= '</div>';
return $res;
}
+
+ /**
+ * @param Item $currentPage
+ */
+ public function setCurrentPage(Item $currentPage): void
+ {
+ $this->_currentPage = $currentPage;
+ }
+
+ /**
+ * @return Item
+ */
+ public function getCurrentPage(): Item
+ {
+ return $this->_currentPage;
+ }
}
protected $table = 'cubist_locales';
protected static $_locales = null;
+ protected static $_mainDomains = [];
protected $_options = ['name' => 'locale',
'singular' => 'langue',
public static function getLocalesDataForFront()
{
+ $current = App::getLocale();
+
$data = self::getLocalesData();
$res = [];
- $active = $data['locales'][$data['default']];
- $res['active_code'] = $data['default'];
+ $active = $data['locales'][$current];
+ $res['active_code'] = $current;
$res['active_flag'] = $active->flag;
- $res['active_name'] = \Cubist\Locale\Locale::translate($data['default'], $data['default']);
+ $res['active_name'] = \Cubist\Locale\Locale::translate($current, $current);
$res['others'] = [];
foreach ($data['locales'] as $code => $locale) {
- if (!$locale->enabled || $code == $data['default']) {
+ if (!$locale->enabled || $code === $current) {
continue;
}
$res['others'][$code] = ['code' => $code, 'flag' => $locale->flag, 'name' => \Cubist\Locale\Locale::translate($code, $code)];
}
return $res;
}
+
+ public static function getMainDomain($locale)
+ {
+ if (!isset(self::$_mainDomains[$locale])) {
+ $all = self::getLocalesData();
+ if (!isset($all[$locale])) {
+ return false;
+ }
+ $domains = $all[$locale]->domains;
+ if (is_string($domains)) {
+ $domains = json_decode($domains, true);
+ }
+ foreach ($domains as $domain) {
+ if ($domain['env'] === App::environment()) {
+ $res = $domain['domain'];
+ break;
+ }
+ }
+ self::$_mainDomains[$locale] = $res ?? false;
+ }
+ return self::$_mainDomains[$locale];
+ }
}