Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed deprecated twig tags #40

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions Resources/views/json-ld.html.twig
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
{% if wo_breadcrumbs()|length %}
{%- apply spaceless -%}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement":
[
{% for b in breadcrumbs %}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement":
[
{% for b in breadcrumbs %}
{
"@type": "ListItem",
"position": {{ loop.index }},
"item":
{
"@type": "ListItem",
"position": {{ loop.index }},
"item":
{
"@id": "{{ b.url }}",
"name": "{% if b.translate is defined and b.translate == true %}{{- b.text | trans(b.translationParameters, translation_domain, locale) -}}{% else %}{{- b.text -}}{% endif %}"
}
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
</script>
{%- endapply -%}
"@id": "{{ b.url }}",
"name": "{% if b.translate is defined and b.translate == true %}{{- b.text | trans(b.translationParameters, translation_domain, locale) -}}{% else %}{{- b.text -}}{% endif %}"
}
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
</script>
{% endif %}
38 changes: 18 additions & 20 deletions Resources/views/microdata.html.twig
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
{% if wo_breadcrumbs()|length %}
{%- apply spaceless -%}
<ol id="{{ listId }}" class="{{ listClass }}" itemscope itemtype="http://schema.org/BreadcrumbList">
{% for b in breadcrumbs %}
<li{% if itemClass is defined and itemClass|length %} class="{{ itemClass }}"{% endif %} itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
{% if b.url and not loop.last %}
<a href="{{ b.url }}" itemprop="item"{% if linkRel is defined and linkRel|length %} rel="{{ linkRel }}"{% endif %}>
{% endif %}
<span itemprop="name">{% if b.translate is defined and b.translate == true %}{{- b.text | trans(b.translationParameters, translation_domain, locale) -}}{% else %}{{- b.text -}}{% endif %}</span>
{% if b.url and not loop.last %}
</a>
{% elseif b.url %}
<meta itemprop="item" content="{{ b.url }}" />
<ol id="{{ listId }}" class="{{ listClass }}" itemscope itemtype="http://schema.org/BreadcrumbList">
{% for b in breadcrumbs %}
<li{% if itemClass is defined and itemClass|length %} class="{{ itemClass }}"{% endif %} itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
{% if b.url and not loop.last %}
<a href="{{ b.url }}" itemprop="item"{% if linkRel is defined and linkRel|length %} rel="{{ linkRel }}"{% endif %}>
{% endif %}
<meta itemprop="position" content="{{ loop.index }}" />
<span itemprop="name">{% if b.translate is defined and b.translate == true %}{{- b.text | trans(b.translationParameters, translation_domain, locale) -}}{% else %}{{- b.text -}}{% endif %}</span>
{% if b.url and not loop.last %}
</a>
{% elseif b.url %}
<meta itemprop="item" content="{{ b.url }}" />
{% endif %}
<meta itemprop="position" content="{{ loop.index }}" />

{% if separator is not null and not loop.last %}
<span class='{{ separatorClass }}'>{{ separator }}</span>
{% endif %}
</li>
{% endfor %}
</ol>
{% endapply %}
{% if separator is not null and not loop.last %}
<span class='{{ separatorClass }}'>{{ separator }}</span>
{% endif %}
</li>
{% endfor %}
</ol>
{% endif %}
45 changes: 39 additions & 6 deletions Test/BundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@ public function testRendering()
/** @var \WhiteOctober\BreadcrumbsBundle\Twig\Extension\BreadcrumbsExtension $breadcrumbsExtension */
$breadcrumbsExtension = $container->get('white_october_breadcrumbs.twig');

self::assertSame(
'<ol id="wo-breadcrumbs" class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList"><li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">foo</span><meta itemprop="position" content="1" /></li></ol>',
self::assertStringEqualsStringIgnoringLineEndings(
<<<'EOD'
<ol id="wo-breadcrumbs" class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList">
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<span itemprop="name">foo</span>
<meta itemprop="position" content="1" />

</li>
</ol>

EOD,
$breadcrumbsExtension->renderBreadcrumbs()
);
}
Expand All @@ -50,8 +59,17 @@ public function testRenderingTranslationWithParameters()
/** @var \WhiteOctober\BreadcrumbsBundle\Twig\Extension\BreadcrumbsExtension $breadcrumbsExtension */
$breadcrumbsExtension = $container->get('white_october_breadcrumbs.twig');

self::assertSame(
'<ol id="wo-breadcrumbs" class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList"><li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">foo__{name:John}</span><meta itemprop="position" content="1" /></li></ol>',
self::assertStringEqualsStringIgnoringLineEndings(
<<<'EOD'
<ol id="wo-breadcrumbs" class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList">
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<span itemprop="name">foo__{name:John}</span>
<meta itemprop="position" content="1" />

</li>
</ol>

EOD,
$breadcrumbsExtension->renderBreadcrumbs([
'viewTemplate' => '@WhiteOctoberBreadcrumbs/microdata.html.twig'
])
Expand All @@ -72,8 +90,23 @@ public function testRenderingTranslationWithParametersAndTranslationDomain()
/** @var \WhiteOctober\BreadcrumbsBundle\Twig\Extension\BreadcrumbsExtension $breadcrumbsExtension */
$breadcrumbsExtension = $container->get('white_october_breadcrumbs.twig');

self::assertSame(
'<ol id="wo-breadcrumbs" class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList"><li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">foo__domain:admin</span><meta itemprop="position" content="1" /><span class=\'separator\'>/</span></li><li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="name">bar__{name:John}__domain:admin</span><meta itemprop="position" content="2" /></li></ol>',
self::assertStringEqualsStringIgnoringLineEndings(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, I didn't know that this one existed! 👍

<<<'EOD'
<ol id="wo-breadcrumbs" class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList">
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<span itemprop="name">foo__domain:admin</span>
<meta itemprop="position" content="1" />

<span class='separator'>/</span>
</li>
<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
<span itemprop="name">bar__{name:John}__domain:admin</span>
<meta itemprop="position" content="2" />

</li>
</ol>

EOD,
$breadcrumbsExtension->renderBreadcrumbs([
'viewTemplate' => '@WhiteOctoberBreadcrumbs/microdata.html.twig',
'translation_domain' => 'admin',
Expand Down
Loading