bdunogier / ezplatform-query-fieldtype
An eZ Platform Field Type that defines a query.
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 2
Open Issues: 3
Type:ezplatform-bundle
Requires
- php: >=7.1
- ezsystems/ezplatform-graphql: ^1.0
Requires (Dev)
- phpspec/phpspec: ^5.1
This package is auto-updated.
Last update: 2019-12-22 12:35:19 UTC
README
This Field Type will let a content manager map an executable Repository Query to a Field.
Example use-cases:
- a
place.nearby_places
field that returns Place items less than X kilometers away from the current content, based on its ownlocation
field - a
gallery.images
field that returns Image items that are children of the current gallery item's main location
The idea is to move content and structure logic implemented in controllers and templates to the repository itself.
Installation
Add the package to the requirements:
composer require ezsystems/ezplatform-query-fieldtype:^1.0@dev
Add the package to app/AppKernel.php
:
$bundles = [ // ... new EzSystems\EzPlatformQueryFieldType\Symfony\EzSystemsEzPlatformQueryFieldTypeBundle(), ];
Add the bundle routes to config/routing.yaml
:
ezplatform.query_fieldtype.routes: resource: '@EzSystemsEzPlatformQueryFieldTypeBundle/Resources/config/routing/' type: directory
Usage
Add a Content query field to a content type.
In the Field Definition settings, select a Query Type from the list, as well as the content type that is returned by that field.
Parameters are used to build the query on runtime. They are either static, or mapped to properties from the content the field value belongs to. The syntax YAML, with the key being the name of a query type parameter, and the value either a scalar, or an expression.
The following variables are available for use in expressions:
string returnedType
: the identifier of the content type that was previously selectedeZ\Publish\API\Values\Content\Content content
: the current content item Also gives you access to fields values. Example with anezurl
field:@=content.getFieldValue('url').link
eZ\Publish\API\Values\Content\ContentInfo contentInfo
: the current content item's content infoeZ\Publish\API\Values\Content\Location mainLocation
: the current content item's main location
A simple example, for a LocationChildren query type that expects:
parent_location_id
: id of the location to fetch children forcontent_types
: content type identifier or array of identifiers to filter on
parent_location_id: "@=mainLocation.id" content_types: "@=returnedType"
See the examples
directory for full examples.