{
$res = [];
+ foreach (Menu::all() as $item) {
+ $res[] = array_merge(['title' => $item->title], self::getLinkData($item->link));
+ }
+ return $res;
+ }
+
+ public static function getLinkData($link)
+ {
$map = ['home' => '/accueil.html',
'resources' => '/ressources.html',
'medialibrary' => '/mediatheque.html',
'fluidbook' => '/coeur/index.html'];
- foreach (Menu::all() as $item) {
- $link = ['title' => $item->title];
- if (str_starts_with($item->link, 'asset_')) {
- $assetId = substr($item->link, 6);
- /** @var Asset $asset */
- $asset = Asset::find($assetId);
- $link['type'] = $asset->type;
- $link['url'] = $asset->getFirstMediaUrl($asset->file_upload);
- } else {
- $link['type'] = 'page';
- $link['url'] = $map[$item->link] ?? $item->link;
- }
- $res[] = $link;
+ $res = [];
+ if (str_starts_with($link, 'asset_')) {
+ $assetId = substr($link, 6);
+ /** @var Asset $asset */
+ $asset = Asset::find($assetId);
+ $res['type'] = $asset->type;
+ $res['url'] = $asset->getFirstMediaUrl($asset->file_upload);
+ } else {
+ $res['type'] = 'page';
+ $res['url'] = isset($map[$link]) ? '/front' . $map[$link] : $link;
}
return $res;
}
use Illuminate\Support\Str;
if (!Str::startsWith($href, 'http') && !Str::startsWith($href, '/tools/')) {
- $map=['home'=>'accueil.html','resources'=>'/ressources.html','medialibrary'=>'/mediatheque.html'];
- if(isset($map[$href])){
- $href=$map[$href];
+ $linkData=\App\Http\Controllers\FrontController::getLinkData($href);
+
+ $href=$linkData['url'];
+ if($linkData['type']==='pdf'){
+ $attributes["@click.prevent"]='openPDF($el.attributes.href.value)';
+ }else if($linkData['type']=='video'){
+ $attributes['@click.prevent']='openPDF($el.attributes.href.value)';
}
- $href = '/front' . $href; // Prefix URLs for frontend preview
}
@endphp