Finding Pages
A lot of the times you need to find a page with a specific type.
Typical example is you have a list of news articles and you want to create deep links into this article on a news page.
Finding a Page
The normal way is to just use the PageFinder
. You can access the page finder by using the PageFinderFactory
.
function doSth (PageFinderFactory $pageFinderFactory)
{
// first create a page finder
$pageFinder = $pageFinderFactory->fromContexts($contentContext, $requestContext);
$pageFinder = $pageFinderFactory->fromRequestContext($requestContext);
$pageFinder = $pageFinderFactory->fromWebsite($website);
// then search for the page
$newsPage = $pageFinder->findFirst(NewsContent::class);
}
The search will return the first accessible page of this type. You need to pass the class name of your content type that you want to search for.
This method will automatically check that the given page is available.
If you ever need to search for a page without also check for accessibility, you can just
get the node tree $pageFinder->getTree()
and search directly. However, you should always
check for the accessibility to not generate dead links for the users (as they maybe can’t access
the page).