-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly resolve internal and external links (#98)
* Correctly resolve internal and external links * Fix functional test cases * Follow multiple levels of internal links * Implement suggestions from code review
- Loading branch information
Showing
8 changed files
with
708 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) Sulu GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\HeadlessBundle\Content\ContentTypeResolver; | ||
|
||
use Sulu\Bundle\HeadlessBundle\Content\ContentView; | ||
use Sulu\Component\Content\Compat\PropertyInterface; | ||
|
||
class ResourceLocatorResolver implements ContentTypeResolverInterface | ||
{ | ||
public static function getContentType(): string | ||
{ | ||
return 'resource_locator'; | ||
} | ||
|
||
public function resolve($data, PropertyInterface $property, string $locale, array $attributes = []): ContentView | ||
{ | ||
$resourceLocator = $data; | ||
$structure = $property->getStructure(); | ||
|
||
// The getResourceLocator method returns the target url for pages of type internal and external link | ||
if (method_exists($structure, 'getResourceLocator')) { | ||
$resourceLocator = $structure->getResourceLocator(); | ||
} | ||
|
||
return new ContentView($resourceLocator); | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
Tests/Functional/Controller/responses/headless_website__test_index.json
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"id": "@uuid@", | ||
"nodeType": 1, | ||
"type": "page", | ||
"template": "default", | ||
"content": { | ||
|
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
"created": "@[email protected]()", | ||
"creator": null, | ||
"id": "@uuid@", | ||
"nodeType": 1, | ||
"template": "default", | ||
"type": "snippet", | ||
"view": { | ||
|
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 |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
} | ||
}, | ||
"id": "@uuid@", | ||
"nodeType": 1, | ||
"template": "default", | ||
"type": "snippet", | ||
"view": { | ||
|
Oops, something went wrong.