Skip to content

Commit 47badd6

Browse files
emodricpspanja
authored andcommitted
Update docs
1 parent 388a88d commit 47badd6

File tree

3 files changed

+212
-0
lines changed

3 files changed

+212
-0
lines changed

Diff for: docs/reference/objects.rst

+118
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,124 @@ Used to filter field relation Locations from the `Field`_ with the given ``$iden
434434
| | |
435435
+----------------------------------------+------------------------------------------------------------------------------------+
436436

437+
``getReverseFieldRelations``
438+
............................
439+
440+
Used to get ``$limit`` reverse field relation Content items from the `Field`_ with the given ``$identifier``. Relations
441+
will be sorted as is defined by the relation field.
442+
443+
+----------------------------------------+------------------------------------------------------------------------------------+
444+
| **Parameters** | 1. ``string $identifier`` |
445+
| | 2. ``int $limit = 25`` |
446+
+----------------------------------------+------------------------------------------------------------------------------------+
447+
| **Returns** | An array of reverse related `Content`_ items |
448+
+----------------------------------------+------------------------------------------------------------------------------------+
449+
| **Sorting method** | Sorted as is defined by the relation `Field`_ |
450+
+----------------------------------------+------------------------------------------------------------------------------------+
451+
| **Example in PHP** | .. code-block:: php |
452+
| | |
453+
| | $relations = $content->getReverseFieldRelations('images', 10); |
454+
| | |
455+
+----------------------------------------+------------------------------------------------------------------------------------+
456+
| **Example in Twig** | .. code-block:: twig |
457+
| | |
458+
| | {% set relations = content.reverseFieldRelations('images') %} |
459+
| | |
460+
+----------------------------------------+------------------------------------------------------------------------------------+
461+
462+
``filterReverseFieldRelations``
463+
...............................
464+
465+
Used to filter reverse field relation Content items from the `Field`_ with the given ``$identifier``.
466+
467+
+----------------------------------------+------------------------------------------------------------------------------------+
468+
| **Parameters** | 1. ``string $identifier`` |
469+
| | 2. ``array $contentTypeIdentifiers = []`` |
470+
| | 3. ``int $maxPerPage = 25`` |
471+
| | 4. ``int $currentPage = 1`` |
472+
+----------------------------------------+------------------------------------------------------------------------------------+
473+
| **Returns** | Pagerfanta instance with reverse related `Content`_ items |
474+
+----------------------------------------+------------------------------------------------------------------------------------+
475+
| **Example in PHP** | .. code-block:: php |
476+
| | |
477+
| | $relations = $content->filterReverseFieldRelations( |
478+
| | 'related_items', |
479+
| | ['images', 'videos'], |
480+
| | 10, |
481+
| | 2 |
482+
| | ); |
483+
| | |
484+
+----------------------------------------+------------------------------------------------------------------------------------+
485+
| **Example in Twig** | .. code-block:: twig |
486+
| | |
487+
| | {% set relations = content.filterReverseFieldRelations( |
488+
| | 'related_items' |
489+
| | ['images', 'videos'] |
490+
| | 10, |
491+
| | 2 |
492+
| | ) %} |
493+
| | |
494+
+----------------------------------------+------------------------------------------------------------------------------------+
495+
496+
``getReverseFieldRelationLocations``
497+
....................................
498+
499+
Used to get ``$limit`` reverse field relation Locations from the `Field`_ with the given ``$identifier``. Relations
500+
will be sorted as is defined by the relation field.
501+
502+
+----------------------------------------+------------------------------------------------------------------------------------+
503+
| **Parameters** | 1. ``string $identifier`` |
504+
| | 2. ``int $limit = 25`` |
505+
+----------------------------------------+------------------------------------------------------------------------------------+
506+
| **Returns** | An array of related `Location`_ items |
507+
+----------------------------------------+------------------------------------------------------------------------------------+
508+
| **Sorting method** | Sorted as is defined by the relation `Field`_ |
509+
+----------------------------------------+------------------------------------------------------------------------------------+
510+
| **Example in PHP** | .. code-block:: php |
511+
| | |
512+
| | $relations = $content->getReverseFieldRelationLocations('images', 10); |
513+
| | |
514+
+----------------------------------------+------------------------------------------------------------------------------------+
515+
| **Example in Twig** | .. code-block:: twig |
516+
| | |
517+
| | {% set relations = content.reverseFieldRelationLocations('images') %} |
518+
| | |
519+
+----------------------------------------+------------------------------------------------------------------------------------+
520+
521+
``filterReverseFieldRelationLocations``
522+
.......................................
523+
524+
Used to filter reverse field relation Locations from the `Field`_ with the given ``$identifier``.
525+
526+
+----------------------------------------+------------------------------------------------------------------------------------+
527+
| **Parameters** | 1. ``string $identifier`` |
528+
| | 2. ``array $contentTypeIdentifiers = []`` |
529+
| | 3. ``int $maxPerPage = 25`` |
530+
| | 4. ``int $currentPage = 1`` |
531+
+----------------------------------------+------------------------------------------------------------------------------------+
532+
| **Returns** | Pagerfanta instance with reverse related `Location`_ items |
533+
+----------------------------------------+------------------------------------------------------------------------------------+
534+
| **Example in PHP** | .. code-block:: php |
535+
| | |
536+
| | $relations = $content->filterReverseFieldRelationLocations( |
537+
| | 'related_items', |
538+
| | ['images', 'videos'], |
539+
| | 10, |
540+
| | 2 |
541+
| | ); |
542+
| | |
543+
+----------------------------------------+------------------------------------------------------------------------------------+
544+
| **Example in Twig** | .. code-block:: twig |
545+
| | |
546+
| | {% set relations = content.filterReverseFieldRelationLocations( |
547+
| | 'related_items' |
548+
| | ['images', 'videos'] |
549+
| | 10, |
550+
| | 2 |
551+
| | ) %} |
552+
| | |
553+
+----------------------------------------+------------------------------------------------------------------------------------+
554+
437555
``getPath``
438556
...........
439557

Diff for: docs/reference/services.rst

+46
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,52 @@ filtering by ContentType.
344344
| | |
345345
+----------------------------------------+------------------------------------------------------------------------------------+
346346

347+
``loadReverseFieldRelations()``
348+
...............................
349+
350+
Get all reverse relation :ref:`Content items<content_object>` from a specific field to a given Content. The method supports optional
351+
filtering by ContentType.
352+
353+
+----------------------------------------+------------------------------------------------------------------------------------+
354+
| **Parameters** | 1. ``Netgen\IbexaSiteApi\API\Values\Content $content`` |
355+
| | 2. ``string $fieldDefinitionIdentifier`` |
356+
| | 3. ``array $contentTypeIdentifiers = []`` |
357+
+----------------------------------------+------------------------------------------------------------------------------------+
358+
| **Returns** | An array of :ref:`Content items<content_object>` |
359+
+----------------------------------------+------------------------------------------------------------------------------------+
360+
| **Example** | .. code-block:: php |
361+
| | |
362+
| | $contentItems = $relationService->loadReverseFieldRelations( |
363+
| | $content, |
364+
| | 'relations', |
365+
| | ['articles'] |
366+
| | ); |
367+
| | |
368+
+----------------------------------------+------------------------------------------------------------------------------------+
369+
370+
``loadReverseFieldRelationLocations()``
371+
.......................................
372+
373+
Get all reverse relation :ref:`Locations<location_object>` from a specific field to a given Content. The method supports optional
374+
filtering by ContentType.
375+
376+
+----------------------------------------+------------------------------------------------------------------------------------+
377+
| **Parameters** | 1. ``Netgen\IbexaSiteApi\API\Values\Content $content`` |
378+
| | 2. ``string $fieldDefinitionIdentifier`` |
379+
| | 3. ``array $contentTypeIdentifiers = []`` |
380+
+----------------------------------------+------------------------------------------------------------------------------------+
381+
| **Returns** | An array of :ref:`Locations<location_object>` |
382+
+----------------------------------------+------------------------------------------------------------------------------------+
383+
| **Example** | .. code-block:: php |
384+
| | |
385+
| | $contentItems = $relationService->loadReverseFieldRelationLocations( |
386+
| | $content, |
387+
| | 'relations', |
388+
| | ['articles'] |
389+
| | ); |
390+
| | |
391+
+----------------------------------------+------------------------------------------------------------------------------------+
392+
347393
Settings
348394
--------
349395

Diff for: docs/reference/templating.rst

+48
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,54 @@ Content Field relations
491491
492492
{{ pagerfanta( events, 'twitter_bootstrap' ) }}
493493
494+
Content Field reverse relations
495+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
496+
497+
- **Accessing all field relations**
498+
499+
This is done by calling the method ``getReverseFieldRelations()``, also available as
500+
``reverseFieldRelations()`` in Twig. It returns an array of Content items and has two parameters:
501+
502+
1. **required** identifier of the reverse relation field
503+
2. **optional** maximum number of items returned, by default ``25``
504+
505+
.. code-block:: twig
506+
507+
{% set reverse_related_articles = content.reverseFieldRelations('related_articles', 10) %}
508+
509+
<ul>
510+
{% for article in reverse_related_articles %}
511+
<li>
512+
<a href="{{ ibexa_path(article) }}">{{ article.name }}</a>
513+
</li>
514+
{% endfor %}
515+
</ul>
516+
517+
- **Filtering through reverse field relations**
518+
519+
This is done by calling the method ``filterReverseFieldRelations()``, which returns a Pagerfanta
520+
instance and has four parameters:
521+
522+
1. **required** identifier of the reverse relation field
523+
2. **optional** array of ContentType identifiers that will be used to filter the result, by
524+
default an empty array ``[]``
525+
3. **optional** maximum number of items per page, by default ``25``
526+
4. **optional** current page, by default ``1``
527+
528+
.. code-block:: twig
529+
530+
{% set articles = content.filterReverseFieldRelations('related_items', ['article'], 10, 1) %}
531+
532+
<ul>
533+
{% for article in articles %}
534+
<li>
535+
<a href="{{ ibexa_path(article) }}">{{ article.name }}</a>
536+
</li>
537+
{% endfor %}
538+
</ul>
539+
540+
{{ pagerfanta( events, 'twitter_bootstrap' ) }}
541+
494542
Location children
495543
~~~~~~~~~~~~~~~~~
496544

0 commit comments

Comments
 (0)