-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Twig extension for to remove highlighter tags, some corrections…
… in SalesChannelRepositoryDecorator,
- Loading branch information
Torsten Freyda
committed
Feb 24, 2024
1 parent
fdb22e2
commit dd4392d
Showing
4 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Resources/views/storefront/component/product/card/box-standard.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{% sw_extends '@Storefront/storefront/component/product/card/box-standard.html.twig' %} | ||
|
||
{% block component_product_box_image_link %} | ||
<a href="{{ seoUrl('frontend.detail.page', { 'productId': id }) }}" | ||
title="{{ muwa_removeHighlightMarkers(name) }}" | ||
class="product-image-link is-{{ displayMode }}"> | ||
{% block component_product_box_image_link_inner %} | ||
{% if cover.url and cover.isSpatialObject() == false %} | ||
{% set attributes = { | ||
'class': 'product-image is-'~displayMode, | ||
'alt': (cover.translated.alt ?: muwa_removeHighlightMarkers(name)), | ||
'title': (cover.translated.title ?: muwa_removeHighlightMarkers(name)), | ||
'loading': 'lazy' | ||
} %} | ||
|
||
{% if displayMode == 'cover' or displayMode == 'contain' %} | ||
{% set attributes = attributes|merge({ 'data-object-fit': displayMode }) %} | ||
{% endif %} | ||
|
||
{% block component_product_box_image_thumbnail %} | ||
{{ parent() }} | ||
{% endblock %} | ||
{% else %} | ||
{% block component_product_box_image_placeholder %} | ||
{{ parent() }} | ||
{% endblock %} | ||
{% endif %} | ||
{% endblock %} | ||
</a> | ||
{% endblock %} | ||
|
||
{% block component_product_box_name %} | ||
<a href="{{ seoUrl('frontend.detail.page', {'productId': id}) }}" | ||
class="product-name" | ||
title="{{ muwa_removeHighlightMarkers(name) }}"> | ||
{{ name|raw }} | ||
</a> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace MuckiSearchPlugin\Twig\Extension; | ||
|
||
use Shopware\Core\Framework\Log\Package; | ||
use Shopware\Core\System\SalesChannel\SalesChannelContext; | ||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
use MuckiSearchPlugin\Services\Settings as PluginSettings; | ||
|
||
#[Package('core')] | ||
class HighlightRemoverExtension extends AbstractExtension | ||
{ | ||
public function __construct( | ||
protected PluginSettings $pluginSettings | ||
) | ||
{} | ||
|
||
public function getFunctions(): array | ||
{ | ||
return [ | ||
new TwigFunction('muwa_removeHighlightMarkers', $this->removeHighlightMarkers(...)), | ||
]; | ||
} | ||
|
||
public function removeHighlightMarkers(string $input): ?string | ||
{ | ||
$replaceItems[] = $this->pluginSettings->getSearchRequestSettingsPreTags(); | ||
$replaceItems[] = $this->pluginSettings->getSearchRequestSettingsPostTags(); | ||
|
||
return str_replace($replaceItems, '', $input); | ||
} | ||
} |