Skip to content

Commit

Permalink
[BUGFIX] Remove doubled base URL in id of list item in BreadcrumbView…
Browse files Browse the repository at this point in the history
…Helper

Resolves: #31
  • Loading branch information
brotkrueml committed Jan 30, 2020
1 parent cc25321 commit facf1a2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Remove doubled base URL in id of list item in BreadcrumbViewHelper (#31)

## [1.5.0] - 2020-01-22

### Added
Expand Down
7 changes: 6 additions & 1 deletion Classes/ViewHelpers/BreadcrumbViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,14 @@ public static function renderStatic(
$webPageTypeClass = $givenItemTypeClass ?: $webPageTypeClass;
}

$id = $arguments[static::ARGUMENT_BREADCRUMB][$i]['link'];
if (\strpos($id, $siteUrl) === false) {
$id = $siteUrl . \ltrim($id, '/');
}

/** @var AbstractType $itemType */
$itemType = new $webPageTypeClass();
$itemType->setId($siteUrl . ltrim($arguments[static::ARGUMENT_BREADCRUMB][$i]['link'], '/'));
$itemType->setId($id);

$item = (new ListItem())->setProperties([
'position' => $i + 1,
Expand Down
17 changes: 17 additions & 0 deletions Tests/Unit/ViewHelpers/BreadcrumbViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ public function fluidTemplatesProvider(): iterable
],
'<script type="application/ld+json">{"@context":"http://schema.org","@type":"BreadcrumbList","itemListElement":{"@type":"ListItem","item":{"@type":"WebPage","@id":"https://example.org/videos/unicorns-in-typo3-land/"},"name":"Unicorns in TYPO3 land","position":"1"}}</script>',
];

yield 'Breadcrumb item with an absolute URL as link given' => [
'<schema:breadcrumb breadcrumb="{breadcrumb}"/>',
[
'breadcrumb' => [
[
'title' => 'A web page',
'link' => '/',
],
[
'title' => 'Unicorns in TYPO3 land',
'link' => 'https://example.org/videos/unicorns-in-typo3-land/',
],
],
],
'<script type="application/ld+json">{"@context":"http://schema.org","@type":"BreadcrumbList","itemListElement":{"@type":"ListItem","item":{"@type":"WebPage","@id":"https://example.org/videos/unicorns-in-typo3-land/"},"name":"Unicorns in TYPO3 land","position":"1"}}</script>',
];
}

/**
Expand Down

0 comments on commit facf1a2

Please sign in to comment.