-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add api endpoint for providing a breadcrumb #70
Comments
We recently added the breadcrumbs of a page directly to the <?php
namespace App\Controller\Website;
use Sulu\Bundle\HeadlessBundle\Controller\HeadlessWebsiteController as SuluHeadlessWebsiteController;
use Sulu\Bundle\WebsiteBundle\Navigation\NavigationMapperInterface;
use Sulu\Component\Content\Compat\StructureInterface;
class HeadlessWebsiteController extends SuluHeadlessWebsiteController
{
/**
* @var NavigationMapperInterface
*/
private $navigationMapper;
public function __construct(
NavigationMapperInterface $navigationMapper
) {
$this->navigationMapper = $navigationMapper;
}
protected function resolveStructure(StructureInterface $structure): array
{
$data = parent::resolveStructure($structure);
$data['breadcrumbs'] = $this->getBreadcrumbs($structure);
return $data;
}
/**
* @return array<array{
* id: string,
* title: string,
* url: string,
* }>
*/
private function getBreadcrumbs(StructureInterface $structure): array
{
$breadcrumbs = [];
foreach ($this->navigationMapper->getBreadcrumb(
$structure->getUuid(),
$structure->getWebspaceKey(),
$structure->getLanguageCode()
) as $item) {
$breadcrumbs[] = [
'uuid' => $item->getUuid(),
'title' => $item->getTitle(),
'url' => $item->getUrl(),
];
}
return $breadcrumbs;
}
} And register that controller in our templates: <controller>App\Controller\Website\HeadlessWebsiteController::indexAction</controller> |
The problem with using As discussed with @chirimoya we should enable or disable the breadcrumb via As we have different cases Page and Article Breadcrumb we maybe adopt the community pull request here: #100 But instead of the current implementation which has a return ['breadcrumb' => $this->getBreadCrumb()]; |
Like the
sulu_breadcrumb
twig extension it should be possible to provide a breadcrumb over an endpoint. It should work similar to the navigation context api.An example api endpint url could be./api/breadcrumb/<uuid>
Another possibility could be that we add the breadcrumb directly to the json response example:
/my-page-url.json?with-breadcrumb=true
Would return the breadcrumb on the root level:
Update:
We want to provide the breadcrumb as a flag in the bundle and directly then via the website controller and an extension pint point in #100. So we avoid an additional request for this kind of data. I'm not yet sure if the extension point need to be in the structureresolver or in the headless controller. I already added a comment to the exist PR to update the interface for our usecase with the breadcrumb.
The text was updated successfully, but these errors were encountered: