View Models
The module provides several view models for handling Prismic content rendering and URL resolution.
Core View Models
DocumentResolver
Handles document context and reference resolution.
LinkResolver
Resolves Prismic document links to Magento URLs.
HtmlSerializer
Handles custom HTML serialization for Rich Text content.
RouteResolver
Manages route resolution for Prismic documents.
Implementation
DocumentResolver
public function hasDocument(): bool
public function getDocument(): \stdClass
public function hasContext(string $documentReference, \stdClass $document = null): bool
public function getContext(string $documentReference, \stdClass $document = null)
LinkResolver
public function resolve($link): ?string
public function getStore(\stdClass $link): StoreInterface
public function resolveRouteUrl(\stdClass $link): ?string
public function resolveDirectPage(\stdClass $link): ?string
HtmlSerializer
Usage Examples
Document Resolution
/** @var $documentResolver DocumentResolver */
if ($documentResolver->hasContext('data.title')) {
$title = $documentResolver->getContext('data.title');
}
Link Resolution
Route Resolution
/** @var $routeResolver RouteResolver */
if ($routeResolver->hasRoute()) {
$route = $routeResolver->getRoute();
}
Best Practices
- Document Handling
- Check document existence
- Handle missing contexts
-
Use proper error handling
-
Link Resolution
- Consider multi-store setup
- Handle missing routes
-
Implement caching
-
Route Management
- Validate routes
- Handle store-specific routes
- Document routing patterns