You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge pull request #20 from ezsystems/ezp31316-pagination_support-1.0
Two new settings are added to the field type:
- a boolean, `EnablePagination`
- an integer, `ItemsPerPage`
# PHP
The `QueryFieldService` is extended with a `QueryFieldPaginationService` interface, with two new methods:
- `loadContentItemsSlice(Content $content, string $fieldDefinitionIdentifier, int $offset, int $limit)`: loads a slice of the results
- `getPaginationConfiguration(Content $content, string $fieldDefinitionIdentifier)`: returns either 0 if pagination is disabled, or the default page size
# Twig
When pagination is enabled for a field, the `QueryResultsInjector` (that adds the Query Field's results to the content view) will set `items` to a `PagerFanta` object (that uses a `QueryResultsPagerFantaAdapter`).
In addition, it will set two extra variables:
- `bool isPaginationEnabled`: used to conditionnally show the pager
- `string pageParameter`: set to the unique page parameter used by the pager. It is named after the field definition identifier. Example: `"[images_page]"`.
# REST
The REST route for query field results now supports offset and limit parameters.
# GraphQL
If a field definition has pagination enabled, the field will return a `Connection` of that type, with the usual arguments (`first`, `last`, `after`, `before`). If no parameter is specified, it will use the items per page option from the field definition.
Copy file name to clipboardExpand all lines: doc/howto/customize_rendering.md
+20-3Lines changed: 20 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,17 @@ In this how-to, you will learn how to customize all the rendering phases.
4
4
5
5
## Rendering process
6
6
Content query fields are rendered using `ez_render_field()`.
7
-
The query is executed, the items iterated on, and each is be displayed using the `line` content view.
7
+
The query is executed, the items iterated on, and each is rendered using the `line` content view.
8
8
9
9
That template renders the content, the view controller, with a custom view type (`content_query_view`). A custom view
10
10
builder executes execute the query, and assigns the results to the view as `items`. The default template for that view (`query_field_view.html.twig`) iterates on each item resulting from the query, and renders each with the `line` view.
11
11
12
+
The field renderer for a query field supports the following parameters:
13
+
-`bool enablePagination`: force pagination enabled, even if it is disabled for that field definition
14
+
-`bool disablePagination`: force pagination disabled, even if it is disabled for that field definition
15
+
-`int itemsPerPage`: sets how many items are displayed per page with pagination. Required if `enablePagination` is
16
+
used and pagination is disabled in the field definition
17
+
12
18
### Summary
13
19
1. Your template: `ez_render_field(content, 'queryfield')`
14
20
2. Field view template: `fieldtype_ui.html.twig`:
@@ -41,16 +47,27 @@ As with any content view, a custom controller can also be defined to further cus
41
47
42
48
Use the `items` iterable to loop over the field's content items:
The usual [content view templates variables](https://doc.ezplatform.com/en/latest/api/field_type_form_and_template/#template-variables) are also available, including `content`, the item that contains the query field.
65
+
In addition to the [usual content view templates variables](https://doc.ezplatform.com/en/latest/api/field_type_form_and_template/#template-variables), the following variables are available:
66
+
- `Content content`: the item that contains the query field.
67
+
- `bool isPaginationEnabled`: indicates if pagination is enabled. When it is, `items` is a `PagerFanta` instance.
68
+
- `string pageParameter`: when pagination is enabled, contains the page parameter to use as the pager fanta
69
+
`pageParameter` argument (important, as it makes every pager unique, required if there are several query
70
+
fields in the same item)
54
71
55
72
## Customizing the line view template
56
73
The line view template, used to render each result, can be customized by creating `line` view configuration rules.
@@ -69,7 +86,7 @@ ezplatform:
69
86
template: "path/to/template.html.twig"
70
87
```
71
88
72
-
The variables are the same as any view template ([documentation]((https://doc.ezplatform.com/en/latest/api/field_type_form_and_template/#template-variables))).
89
+
The variables are the same than other view template ([documentation]((https://doc.ezplatform.com/en/latest/api/field_type_form_and_template/#template-variables))).
0 commit comments