Add NovaeZExtraBundle in your composer.json:
{
"require": {
"novactive/ezextrabundle": "dev-master"
}
}
Now tell composer to download the bundle by running the command:
$ composer.phar update novactive/ezextrabundle
<?php
// ezpublish/EzPublishKernel.php
public function registerBundles() {
$bundles = array(
// ...
new Novactive\Bundle\eZExtraBundle\NovaeZExtraBundle(),
);
}
Activate the "dev" routes:
_novaezetraRoutesDev:
resource: "@NovaeZExtraBundle/Resources/config/routing/dev.yml"
Activate the "prod" routes:
_novaezextraRoutes:
resource: "@NovaeZExtraBundle/Resources/config/routing/main.yml"
php app|ezpublish/console cache:clear --env=dev
Go to : /_novaezextra/dev/test
{% set content = eznova_content_by_contentinfo( location.contentInfo ) %}
{% set contentType = eznova_contenttype_by_content( content ) %}
{% set contentType = eznova_parentcontent_by_contentinfo( content ) %}
Note : you get the content of the parent on the main location
{% set contentType = eznova_location_by_content( content ) %}
{% set content = eznova_relation_field_to_content( ez_field_value( content, 'internal_link' ) ) %}
Note : return the direct linked content by the relation object FieldType
{% set content = eznova_relationlist_field_to_content_list( ez_field_value( content, 'internal_links' ) ) %}
Note : return an array of direct linked contents by the relation objects FieldType
{{ render( controller( "eZNovaExtraBundle:Picture:alias", { "contentId": content.getField('picture').value.destinationContentId, "fieldIdentifier": "image", "alias": "large" })) }}
The goal was to mimic the old Fetch Content List
public function contentTree( $parentLocationId, $typeIdentifiers = [], $sortClauses = [], $limit = null, $offset = 0, $additionnalCriterion );
public function contentList( $parentLocationId, $typeIdentifiers = [], $sortClauses = [], $limit = null, $offset = 0, $additionnalCriterion );
public function nextByAttribute( $locationId, $attributeIdentifier, $locale, $additionnalCriterions = [] );
public function nextByPriority( $locationId, $aditionnalCriterions = [] )
public function previousByAttribute( $locationId, $attributeIdentifier, $locale, $additionnalCriterion = [] )
public function previousByPriority( $locationId, $additionnalCriterion = [] )
Return an array of Result
Usage:
{% for child in children %}
<h2>{{ ez_field_value( child.content, "title" ) }}</h2>
{{ ez_render_field( child.content, "overview" ) }}
<a href="{{ path( "ez_urlalias", { "locationId" : child.content.contentInfo.mainLocationId } ) }}">{{ "Learn more" | trans() }}</a>
{% endfor %}
Simply inject the children ( and potentially other things on a view Full )
Add your provider in a folder of your bundle
project.home_page.children.provider:
class: Project\Bundle\GeneralBundle\ChildrenProvider\YOUCONTENTIDENTIFIERPROVIDERCLASS
parent: novactive.ezextra.abstract.children.provider
tags:
- { name: novactive.ezextra.children.provider, contentTypeIdentifier: YOUCONTENTIDENTIFIER }
You class YOUCONTENTIDENTIFIERPROVIDERCLASS must extend Novactive\Bundle\eZExtraBundle\EventListener\Type
After you need to create a method for each view you display if you want to get children in your template The goal is to have children on each view.
Ex:
namespace Yoochoose\Bundle\GeneralBundle\ChildrenProvider;
use Novactive\Bundle\eZExtraBundle\EventListener\Type;
use eZ\Publish\API\Repository\Values\Content\Query;
class PersonalizationEngine extends Type
{
//its also use as default to get the full view children
public function getChildren($viewParameters, SiteAccess $siteAccess = null)
{
return $this->contentHelper->contentList( $this->location->id, [ 'article' ], array( new Query\SortClause\Location\Priority( Query::SORT_ASC ) ), 10);
}
public function getLineChildren( $viewParameters )
{
...
}
}