186 lines
6.5 KiB
PHP
186 lines
6.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Contracts\Directories\ProductDirectory;
|
|
use App\Contracts\Directories\RecipeDirectory;
|
|
use Diglactic\Breadcrumbs\Breadcrumbs;
|
|
use Diglactic\Breadcrumbs\Generator;
|
|
use Domain\Models\Entities\Product;
|
|
use Domain\Models\Entities\Recipe;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
use Uwil\LaravelDynamicPages\Enums\PageStatusEnum;
|
|
use Uwil\LaravelDynamicPages\Helpers\RouteHelper;
|
|
use Uwil\LaravelDynamicPages\Models\DynamicPage;
|
|
|
|
// FIXME: This should be refactored, a work has to be done in coordination with the concerned package.
|
|
if (! Schema::hasTable((new DynamicPage())->getTable())) {
|
|
return;
|
|
}
|
|
|
|
$currentLocale = app()->getLocale();
|
|
$supportedLocales = LaravelLocalization::getSupportedLanguagesKeys();
|
|
|
|
$pageHome = DynamicPage::getModelsCached()
|
|
->where('status', PageStatusEnum::published)
|
|
->where('isRoot', true)
|
|
->first();
|
|
DynamicPage::getModelsCached()->map(function (DynamicPage $dynamicPageModel) use ($supportedLocales, $pageHome) {
|
|
collect($supportedLocales)->map(function (string $locale) use ($dynamicPageModel, $pageHome) {
|
|
Breadcrumbs::for(
|
|
sprintf('front.dynamic-pages.%s.%s', $dynamicPageModel->id_key, $locale),
|
|
function (Generator $trail) use ($locale, $dynamicPageModel, $pageHome) {
|
|
if (! is_null($dynamicPageModel->page_id)) {
|
|
$trail->parent(sprintf(
|
|
'front.dynamic-pages.%s.%s',
|
|
$dynamicPageModel->parentPage->id_key,
|
|
$locale,
|
|
));
|
|
} elseif (isset($pageHome) && $dynamicPageModel->id_key !== $pageHome->id_key) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $locale));
|
|
}
|
|
$trail->push(
|
|
$dynamicPageModel->title,
|
|
RouteHelper::routeNameChecker(sprintf('front.dynamic-pages.%s', $dynamicPageModel->id_key))
|
|
);
|
|
}
|
|
);
|
|
});
|
|
});
|
|
|
|
Breadcrumbs::for('front.engage', function (Generator $trail) {
|
|
$currentLocale = app()->getLocale();
|
|
$pageHome = DynamicPage::getModelsCached()
|
|
->where('status', PageStatusEnum::published)
|
|
->where('isRoot', true)
|
|
->first();
|
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
ucfirst(__('front.ovoteam_commit')),
|
|
route('front.engage')
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.made-in-france', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
$currentLocale = app()->getLocale();
|
|
$pageHome = DynamicPage::getModelsCached()
|
|
->where('status', PageStatusEnum::published)
|
|
->where('isRoot', true)
|
|
->first();
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
ucfirst(__('front.ovoteam_commit')),
|
|
route('front.engage')
|
|
);
|
|
$trail->push(
|
|
trans('front.made-in-france'),
|
|
route('front.made-in-france')
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.expertise', function (Generator $trail) use ($currentLocale, $pageHome) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
ucfirst(__('front.ovoteam_commit')),
|
|
route('front.engage')
|
|
);
|
|
$trail->push(
|
|
trans('front.expertise'),
|
|
route('front.expertise')
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.gamme', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
ucfirst(__('front.ovoteam_commit')),
|
|
route('front.engage')
|
|
);
|
|
$trail->push(
|
|
trans('front.gamme'),
|
|
route('front.gamme')
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.contact-us', function (Generator $trail) use ($currentLocale, $pageHome) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
trans('front.contactpage'),
|
|
route('front.contact-us')
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.search', function (Generator $trail) use ($currentLocale, $pageHome) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
trans('front.search'),
|
|
route('front.search')
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.products.index', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
trans('front.titles.products'),
|
|
route('front.products.index')
|
|
);
|
|
});
|
|
Breadcrumbs::for('front.products.show', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
$productDirectory = app(ProductDirectory::class);
|
|
$product = request()->route('product');
|
|
|
|
if (! $product instanceof Product) {
|
|
$product = $productDirectory->findBySlug((string) $product);
|
|
}
|
|
|
|
if (! $product instanceof Product) {
|
|
Log::warning('Product not found for breadcrumb generation.');
|
|
|
|
return;
|
|
}
|
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
trans('front.titles.products'),
|
|
route('front.products.index')
|
|
);
|
|
$trail->push(
|
|
$product->name,
|
|
route('front.products.show', ['product' => $product->slug ?? $product->id])
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.recipes.index', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
trans('front.titles.recipes'),
|
|
route('front.recipes.index')
|
|
);
|
|
});
|
|
Breadcrumbs::for('front.recipes.show', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
$recipeDirectory = app(RecipeDirectory::class);
|
|
$recipe = request()->route('recipe');
|
|
|
|
if (! $recipe instanceof Recipe) {
|
|
$recipe = $recipeDirectory->findBySlug((string) $recipe);
|
|
}
|
|
|
|
if (! $recipe instanceof Recipe) {
|
|
Log::warning('Recipe not found for breadcrumb generation.');
|
|
|
|
return;
|
|
}
|
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
trans('front.titles.recipes'),
|
|
route('front.recipes.index')
|
|
);
|
|
$trail->push(
|
|
$recipe->name,
|
|
route('front.recipes.show', ['recipe' => $recipe->slug ?? $recipe->id])
|
|
);
|
|
});
|