ldc-ovoteam/routes/breadcrumbs/front.php

175 lines
6.1 KiB
PHP
Raw Permalink Normal View History

2026-03-16 12:36:44 +01:00
<?php
declare(strict_types=1);
use App\Dto\ProductDto;
use App\Dto\RecipeDto;
2026-03-16 12:36:44 +01:00
use Diglactic\Breadcrumbs\Breadcrumbs;
use Diglactic\Breadcrumbs\Generator;
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;
2026-03-16 12:36:44 +01:00
// 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) {
2026-04-08 13:59:30 +02:00
$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')
);
});
2026-04-08 13:59:30 +02:00
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')
);
});
2026-04-08 13:59:30 +02:00
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')
);
});
2026-04-08 13:59:30 +02:00
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')
);
2026-03-16 12:36:44 +01:00
$trail->push(
trans('front.gamme'),
route('front.gamme')
2026-03-16 12:36:44 +01:00
);
});
2026-04-15 09:31:43 +02:00
Breadcrumbs::for('front.contact-us', function (Generator $trail) use ($currentLocale, $pageHome) {
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
2026-04-15 09:31:43 +02:00
$trail->push(
trans('front.contactpage'),
2026-04-15 09:31:43 +02:00
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));
2026-04-15 09:31:43 +02:00
$trail->push(
trans('front.search'),
2026-04-15 09:31:43 +02:00
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')
);
});
feat(directory): update ProductDirectory to use ProductId - Changed the find method to accept ProductId instead of int. - Added findBySlug method to retrieve products by slug. - Updated getCategoryProducts method to return CategoryProducts type. feat(eloquent): implement findBySlug in EloquentProductDirectory - Implemented findBySlug method to retrieve products by slug. - Updated find method to handle ProductId. feat(dto): enhance CategoryProducts to serialize product IDs - Updated CategoryProducts to serialize product IDs as strings. feat(controller): modify ProductController to handle search limits - Set limitPerCategory to -1 for search functionality. refactor(model): change Product model ID to UUID - Changed the id field in Product model to UUID. - Updated related methods to handle UUIDs. feat(migration): alter products and recipes tables for UUIDs - Updated migrations to use UUIDs for primary keys in products and recipes tables. - Adjusted foreign key constraints in product_recipe table. feat(route): add route model binding for products - Implemented route model binding for products using ProductId and slug. chore(seed): remove CSV import calls from MandatorySeeder - Removed calls to ImportProductsCsvSeeder and ImportRecipesCsvSeeder. feat(entity): create ProductId and RecipeId value objects - Added ProductId and RecipeId classes to encapsulate UUIDs. feat(frontend): update TypeScript interfaces for products - Updated TypeScript interfaces to reflect changes in product structure.
2026-07-08 16:32:12 +02:00
Breadcrumbs::for('front.products.show', function (Generator $trail) use ($pageHome, $currentLocale) {
$product = request()->route('frontProduct');
feat(directory): update ProductDirectory to use ProductId - Changed the find method to accept ProductId instead of int. - Added findBySlug method to retrieve products by slug. - Updated getCategoryProducts method to return CategoryProducts type. feat(eloquent): implement findBySlug in EloquentProductDirectory - Implemented findBySlug method to retrieve products by slug. - Updated find method to handle ProductId. feat(dto): enhance CategoryProducts to serialize product IDs - Updated CategoryProducts to serialize product IDs as strings. feat(controller): modify ProductController to handle search limits - Set limitPerCategory to -1 for search functionality. refactor(model): change Product model ID to UUID - Changed the id field in Product model to UUID. - Updated related methods to handle UUIDs. feat(migration): alter products and recipes tables for UUIDs - Updated migrations to use UUIDs for primary keys in products and recipes tables. - Adjusted foreign key constraints in product_recipe table. feat(route): add route model binding for products - Implemented route model binding for products using ProductId and slug. chore(seed): remove CSV import calls from MandatorySeeder - Removed calls to ImportProductsCsvSeeder and ImportRecipesCsvSeeder. feat(entity): create ProductId and RecipeId value objects - Added ProductId and RecipeId classes to encapsulate UUIDs. feat(frontend): update TypeScript interfaces for products - Updated TypeScript interfaces to reflect changes in product structure.
2026-07-08 16:32:12 +02:00
if (! $product instanceof ProductDto) {
Log::warning('Product not found for breadcrumb generation.');
return;
feat(directory): update ProductDirectory to use ProductId - Changed the find method to accept ProductId instead of int. - Added findBySlug method to retrieve products by slug. - Updated getCategoryProducts method to return CategoryProducts type. feat(eloquent): implement findBySlug in EloquentProductDirectory - Implemented findBySlug method to retrieve products by slug. - Updated find method to handle ProductId. feat(dto): enhance CategoryProducts to serialize product IDs - Updated CategoryProducts to serialize product IDs as strings. feat(controller): modify ProductController to handle search limits - Set limitPerCategory to -1 for search functionality. refactor(model): change Product model ID to UUID - Changed the id field in Product model to UUID. - Updated related methods to handle UUIDs. feat(migration): alter products and recipes tables for UUIDs - Updated migrations to use UUIDs for primary keys in products and recipes tables. - Adjusted foreign key constraints in product_recipe table. feat(route): add route model binding for products - Implemented route model binding for products using ProductId and slug. chore(seed): remove CSV import calls from MandatorySeeder - Removed calls to ImportProductsCsvSeeder and ImportRecipesCsvSeeder. feat(entity): create ProductId and RecipeId value objects - Added ProductId and RecipeId classes to encapsulate UUIDs. feat(frontend): update TypeScript interfaces for products - Updated TypeScript interfaces to reflect changes in product structure.
2026-07-08 16:32:12 +02:00
}
$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', ['frontProduct' => $product->slug])
);
});
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) {
$recipe = request()->route('frontRecipe');
if (! $recipe instanceof RecipeDto) {
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', ['frontRecipe' => $recipe->slug])
);
});