Skip to content

Commit 3f74643

Browse files
committed
Add Hyva support + fix template file resolution
1 parent bca0c23 commit 3f74643

File tree

5 files changed

+54
-9
lines changed

5 files changed

+54
-9
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ bin/magento setup:upgrade
4141

4242
## Features
4343

44-
This module render server-sided product breadcrumbs so it's visible to any robot without requiring any js loads and process.
45-
Can you still enable the js breadcrumbs so your user can see natural breadcrumbs following their navigation.
44+
This module is Hyvä-Ready!
4645

47-
If your store use Hyva theme, this module works out-of-the-box when the breadcrumbs is server-side rendering. If you want
48-
to print a default breadcrumb then override it with client-side rendering, you need to override the client-side rendered
49-
breadcrumbs template and update the script.
46+
This module render server-sided product breadcrumbs so it's visible to any robot without requiring any js loads and process.
47+
Can you still enable the js breadcrumbs so your user can see natural breadcrumbs following their navigation.
5048

5149
## Documentation
5250

etc/adminhtml/system.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
<system>
1010
<section id="catalog">
1111
<group id="seo">
12-
<field id="render_product_breadcrumbs_server_side" translate="label comment" type="select" sortOrder="30" showInDefault="1" canRestore="1">
12+
<field id="render_product_breadcrumbs_server_side" translate="label" type="select" sortOrder="30" showInDefault="1" canRestore="1">
1313
<label>Render Product Breadcrumbs from Server-Side</label>
14-
<comment>This setting depends of the theme. If your store use Hyva theme, disable client-side breadcrumbs rendering.</comment>
1514
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1615
<config_path>catalog/seo/render_product_breadcrumbs_server_side</config_path>
1716
</field>
1817
<field id="override_product_breadcrumbs_client_side" translate="label comment" type="select" sortOrder="31" showInDefault="1" canRestore="1">
1918
<label>Override Product Breadcrumbs on Client-Side</label>
20-
<comment>If your store use Hyva theme, this setting is by-passed. You may want to enable the Hyva client-side breadcrumbs rendering.</comment>
19+
<comment>If you enable override and your store use Hyvä theme, you must enable the Hyvä client-side breadcrumbs rendering.</comment>
2120
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2221
<config_path>catalog/seo/override_product_breadcrumbs_client_side</config_path>
2322
</field>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © OpenGento, All rights reserved.
5+
* See LICENSE bundled with this library for license details.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9+
<body>
10+
<referenceBlock name="product_breadcrumbs">
11+
<arguments>
12+
<argument name="client_side_rendered_crumbs_template" xsi:type="string">Opengento_ProductBreadcrumbs::hyvä/product/breadcrumbs.phtml</argument>
13+
</arguments>
14+
</referenceBlock>
15+
</body>
16+
</page>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © OpenGento, All rights reserved.
4+
* See LICENSE bundled with this library for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Hyvä\Theme\Model\ViewModelRegistry;
9+
use Magento\Framework\Escaper;
10+
use Magento\Theme\Block\Html\Breadcrumbs as BreadcrumbsBlock;
11+
use Opengento\ProductBreadcrumbs\ViewModel\Product\Breadcrumbs as BreadcrumbsConfig;
12+
13+
/** @var ViewModelRegistry $viewModels */
14+
/** @var Escaper $escaper */
15+
/** @var BreadcrumbsBlock $block */
16+
17+
/** @var BreadcrumbsConfig $config */
18+
$config = $viewModels->require(BreadcrumbsConfig::class);
19+
?>
20+
<div id="product_breadcrumbs" x-init="generateProductBreadcrumbsOnProductPage()">
21+
<?php if ($config->isServerSideRendered()): ?>
22+
<?= $block->fetchView($block->getTemplateFile('Magento_Theme::html/breadcrumbs.phtml')) ?>
23+
<?php endif; ?>
24+
</div>
25+
<script>
26+
function generateProductBreadcrumbsOnProductPage() {
27+
<?php if (!$config->isServerSideRendered() || $config->isClientSideOverrideAllowed()): ?>
28+
<?php $breadcrumbsTemplate = '<div id="product_breadcrumbs">' . $block->fetchView($block->getTemplateFile('Magento_Catalog::product/view/breadcrumbs.phtml')) . '</div>'; ?>
29+
hyvä.replaceDomElement('#product_breadcrumbs', '<?= $escaper->escapeJs($breadcrumbsTemplate) ?>');
30+
<?php endif; ?>
31+
}
32+
</script>

view/frontend/templates/product/breadcrumbs.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $viewModel = $block->getData('viewModel');
1818
$config = $block->getData('breadcrumbsConfig');
1919
?>
2020
<?php if ($config->isServerSideRendered()): ?>
21-
<?= $block->fetchView('Magento_Theme::html/breadcrumbs.phtml') ?>
21+
<?= $block->fetchView($block->getTemplateFile('Magento_Theme::html/breadcrumbs.phtml')) ?>
2222
<?php else: ?>
2323
<div class="breadcrumbs"></div>
2424
<?php endif; ?>

0 commit comments

Comments
 (0)