eZ Platform bundle to hold utilities.
This is an eZ Publish 5 Symfony bundle to hold utilities.
Run composer require
:
$ composer require contextualcode/utility-bundle
Enable the bundle in app/AppKernel.php
(ezpublish/EzPublishKernel.php
) by adding this line in the registerBundles
method:
public function registerBundles()
{
$bundles = array(
...
new ContextualCode\UtilityBundle\ContextualCodeUtilityBundle(),
...
);
Add the UtilityService as a Twig global variable (in app/config/config.yml
or ezpublish/config/config.yml
):
twig:
globals:
cc_utilities: "@contextualcode.utility.utilityservice"
There are many different utility functions provided by this bundle.
fetch
Quick example of calling fetch
from a Twig template to get all Banner objects in the current node:
{% set banners = cc_utilities.fetch({
'parentLocation': location,
'classFilter': 'banner',
'depth': 1,
'loadContent': true,
'sortClause': 'priority',
'sortOrder': 'desc'
})
%}
This will return an array with each value having keys location
and content
.
Another example, to grab the closest alert
item from the current node upwards with persistent
attribute checked, sorted by priority and then name:
{% set paths = location.pathString|split('/')|reverse %}
{% set found_alert = false %}
{% for locationID in paths if not found_alert and locationID %}
{% set alert = cc_utilities.fetch({
'parentLocationID': locationID,
'classFilter': 'alert',
'sortClauses': [ 'priority', 'name' ],
'sortOrders': [ 'desc', 'desc' ],
'loadContent': true,
'depth': 1,
'limit': 1,
'attributeFilter': [
[ 'persistent', 'eq', true ]
]
})
%}
{% set found_alert = alert|length > 0 %}
{% endfor %}
fetch
ParametersRequired:
parentLocationID
or parentLocation
Optional:
loadContent
content
key of each item.bool
false
ignoreVisibility
bool
false
limit
string
or int
or null
null
offset
int
0
depth
parentLocation
.depthOperator
.string
or array
or int
or null
null
depthOperator
depth
limit.string
, one of: 'contains', 'between'
, 'eq'
, 'gt'
, 'gte'
, 'in'
, 'lt'
, 'lte'
'eq'
priority
priorityOperator
.string
or array
or int
or null
null
priorityOperator
priority
limit.string
, one of: 'between'
, 'gt'
, 'gte'
, 'lt'
, 'lte'
'lte'
sectionFilter
sectionFilterOperator
.string
or array
or int
or null
null
sectionFilterOperator
sectionFilter
.string
, one of: 'or'
, 'not'
'or'
classFilter
classFilterOperator
.string
or array
or int
or null
null
classFilterOperator
classFilter
.string
, one of: 'or'
, 'not'
'or'
attributeFilter
[ $field_identifier, $operator, $field_value ]
, where $operator
is one of: 'between'
, 'eq'
, 'gt'
, 'gte'
, 'in'
, 'like'
, 'lt'
, 'lte'
array
of array
s or null
null
attributeFilterOperator
attributeFilter
.string
, one of: 'and'
, 'or'
, 'not'
'and'
sortClause
sortClauses
).sortOrder
.null
(which uses the parent location's sort clause), or string
, one of: 'path'
, 'published'
, 'modified'
, 'section'
, 'depth'
, 'priority'
, 'name'
, 'contentobject_id'
null
(which uses the parent location's sort clause)sortOrder
sortClause
.null
(which uses the parent location's sort order), or string
, one of: 'asc'
, 'desc'
null
(which uses the parent location's sort order)sortClauses
sortClause
, but you can pass multiple as an array (for secondary, tertiary, etc. sorting).sortOrders
.array
of valid values for sortClause
.array(null)
sortOrders
sortOrder
, but you can pass multiple as an array (for secondary, tertiary, etc. sorting).sortClauses
. If the sortClauses
and sortOrders
are different lengths, the defaults are used for the missing values.array
of valid values for sortOrders
.array(null)
getContent($contentID, $lang = 'eng-US')
getContentFromLocationID($locationID, $lang = 'eng-US')
getContentFromLocation($location, $lang = 'eng-US')
getContentInfo($contentID, $lang = 'eng-US')
getParentLocationFromLocation($location)
getParentLocationIDFromLocation($location)
getParentLocationIDFromLocationID($locationID)
getParentLocationIDFromLocationID($locationID)
getParentLocationIDFromLocationID($locationID)
getMainLocationIDFromContentID($contentID)
getContentFromRelationAttribute($content, $attributeID, $lang = 'eng-US')
If passed an $attributeID
for an Object Relation attribute, content will be returned.
If passed an $attributeID
for an Object Relations attribute, an array of content will be returned.
getContentInfoFromRelationAttribute($content, $attributeID, $lang = 'eng-US')
If passed an $attributeID
for an Object Relation attribute, content info will be returned.
If passed an $attributeID
for an Object Relations attribute, an array of content infos will be returned.
getAttributeID($content, $attributeID)
getFileAttributeFileName($content, $attributeID)
getContentDownloadURL($content, $attributeID)
More documentation to come.