Skip to content

Commit

Permalink
Merge pull request #40 from basdenooijer/fix-twig-deprecations
Browse files Browse the repository at this point in the history
Removed deprecated twig tags
  • Loading branch information
mhujer authored Sep 16, 2024
2 parents a1676d7 + 51a1d76 commit a2cde1f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 47 deletions.
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(
<<<'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

0 comments on commit a2cde1f

Please sign in to comment.