The ErdnaxelaWeb\IbexaDesignIntegration\Pager\PagerBuilder is a service that facilitates creating paginated results from Ibexa search operations.
It provides a streamlined interface for building customizable, filterable, and configurable pagers that can be used throughout your application.
The primary purpose of the PagerBuilder is to:
- Abstract the complexity of creating search queries and pagination
- Provide a unified interface for different search types (content, locations, custom)
- Support filtering, sorting, and other search operations
- Allow for event-based customization of search queries
- Create consistent pagination objects across the application
PagerBuilder uses a configuration-driven approach where each pager is defined by a type identifier that maps to a specific configuration:
$pager = $pagerBuilder->build('article_list');The configuration defines search parameters, display options, and filtering capabilities for each pager type.
The PagerBuilder uses a search type system to adapt to different data sources and search requirements:
- Search Type Factories: Each search type is provided by a factory registered with a specific identifier
- Contextual Queries: Search types can adjust their behavior based on context, request parameters, or default data
- Adapters: Each search type provides the appropriate Pagerfanta adapter for the data source
The search query can be modified through events, allowing for:
- Query Criterion Modification: Add or modify search criteria
- Filter Criterion Modification: Adjust filtering criteria
- Aggregation Addition: Add custom aggregations for search facets
- Context-Specific Modifications: Different modifications can be applied depending on the pager type
PagerBuilder integrates with Symfony forms for search and filtering:
- Search Forms: Built through the
ErdnaxelaWeb\IbexaDesignIntegration\Pager\PagerSearchFormBuilder - Active Filters: Managed by the
ErdnaxelaWeb\IbexaDesignIntegration\Pager\PagerActiveFiltersListBuilder
// In a controller
$pager = $this->pagerBuilder->build('article_list');
// Pass to template
return $this->render('articles/list.html.twig', [
'pager' => $pager,
]);// Provide context that might influence the search
$pager = $this->pagerBuilder->build('article_list', [
'category' => 'technology',
'featured' => true,
]);// Set default search parameters
$searchData = new SearchData();
$searchData->setSortField('published_date');
$searchData->setSortOrder('desc');
$pager = $this->pagerBuilder->build('article_list', [], $searchData);Pager configurations are managed by the PagerConfigurationManager and typically defined in configuration files:
pagers:
article_list:
searchType: 'content'
maxPerPage: 12
headlineCount: 3
disablePagination: true # When true, the returned pager iterator autoswitch page
sortOptions:
- { field: 'published_date', order: 'desc', label: 'Most recent' }
- { field: 'title', order: 'asc', label: 'Alphabetical' }
filterOptions:
- { field: 'category', type: 'select', label: 'Category' }The PagerBuilder dispatches events at key points during the build process:
- Global Event:
ErdnaxelaWeb\IbexaDesignIntegration\Event\PagerBuildEvent::GLOBAL_PAGER_BUILDis dispatched for all pagers - Type-Specific Event:
ErdnaxelaWeb\IbexaDesignIntegration\Event\PagerBuildEvent::getEventName($type)is dispatched for a specific pager type
Event subscribers can modify the search query by adding criteria, filters, or aggregations:
public function onBuildArticleList(PagerBuildEvent $event)
{
if ($event->context['featured'] ?? false) {
$event->queryCriterions[] = new Criterion\Field('featured', Criterion\Operator::EQ, true);
}
}The PagerBuilder integrates with the content transformation system:
- Content Transformation: Results are automatically transformed using the
ErdnaxelaWeb\IbexaDesignIntegration\Transformer\ContentTransformer
- Consistency: Creates consistent pagination behavior across the application
- Flexibility: Supports different search types and configurations
- Extensibility: Can be extended through events and custom search types
- Performance: Optimized for Ibexa search operations
- Developer Experience: Simplifies the creation of paginated content listings
The PagerBuilder is a key component for creating efficient, flexible, and user-friendly paginated listings in Ibexa CMS applications.