new file: olm-login.php
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace KbMarkdownImporter\Frontend;
|
||||
|
||||
use KbMarkdownImporter\Plugin;
|
||||
use KbMarkdownImporter\Repository\ProductRepository;
|
||||
|
||||
final class UrlBuilder
|
||||
{
|
||||
@@ -41,9 +42,40 @@ final class UrlBuilder
|
||||
|
||||
public static function page(string $productSlug, string $versionSlug, string $pageSlug = ''): string
|
||||
{
|
||||
[$productSlug, $pageSlug] = self::normalizeProductRoute($productSlug, $pageSlug);
|
||||
|
||||
return self::route('page', $productSlug, $versionSlug, $pageSlug);
|
||||
}
|
||||
|
||||
private static function normalizeProductRoute(string $productSlug, string $pageSlug): array
|
||||
{
|
||||
$term = get_term_by('slug', $productSlug, 'kb_product');
|
||||
|
||||
if (! $term instanceof \WP_Term) {
|
||||
return [$productSlug, $pageSlug];
|
||||
}
|
||||
|
||||
$repository = new ProductRepository();
|
||||
$meta = $repository->frontendMeta($term);
|
||||
$groupSlug = (string) $meta['group_slug'];
|
||||
$groupTermCount = 0;
|
||||
$terms = get_terms(['taxonomy' => 'kb_product', 'hide_empty' => false]);
|
||||
|
||||
if (! is_wp_error($terms)) {
|
||||
foreach ($terms as $candidate) {
|
||||
if ($groupSlug === (string) $repository->frontendMeta($candidate)['group_slug']) {
|
||||
$groupTermCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($groupTermCount > 1 && ! str_contains($pageSlug, '--')) {
|
||||
$pageSlug = $term->slug . '--' . ($pageSlug ?: 'index');
|
||||
}
|
||||
|
||||
return [$groupSlug, $pageSlug];
|
||||
}
|
||||
|
||||
private static function route(string $route, string $productSlug = '', string $versionSlug = '', string $pageSlug = ''): string
|
||||
{
|
||||
if (self::isEmbed()) {
|
||||
|
||||
Reference in New Issue
Block a user