Skip to main content

Custom Configuration

If the available configurability is not sufficient, you can now extend the configuration with your own fields.

Eventlistener

Create an eventlistener that listens to the NewsEvents::NEWS_BRICK_QUERY_BUILD event

<?php

namespace App\EventListener;

use OpenDxp\Bundle\NewsBundle\Event\NewsBrickEvent;
use OpenDxp\Bundle\NewsBundle\NewsEvents;
use OpenDxp\Model\Document\PageSnippet;
use OpenDxp\Model\Document\Tag\Relations;
use OpenDxp\Templating\Renderer\TagRenderer;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class NewsBrickModifierListener implements EventSubscriberInterface
{
/**
* @var TagRenderer
*/
protected $tagRenderer;

/**
* @param TagRenderer $tagRenderer
*/
public function __construct(TagRenderer $tagRenderer)
{
$this->tagRenderer = $tagRenderer;
}

/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
NewsEvents::NEWS_BRICK_QUERY_BUILD => 'modifyBrick'
];
}

/**
* @param NewsBrickEvent $event
*/
public function modifyBrick(NewsBrickEvent $event)
{
$querySettings = $event->getQuerySettings();
$document = $event->getInfo()->getDocument();

$configuration = $this->getDocumentTag($document, '<yourpropertytype>', '<yourproperty>');

# crucial: check properly
if (!$configuration instanceof Relations) {
return;
}

$elements = $configuration->getElements(); // or whatever Method applies to your Class
$querySettings['<yourproperty>'] = $elements;
$event->setQuerySettings($querySettings);
}

/**
* @param PageSnippet $document
* @param string $type
* @param string $inputName
* @param array $options
*
* @return \OpenDxp\Model\Document\Tag|null
*/
protected function getDocumentTag(PageSnippet $document, $type, $inputName, array $options = [])
{
return $this->tagRenderer->getTag($document, $type, $inputName, $options);
}
}

Service registration

services:
App\EventListener\NewsBrickModifierListener:
autowire: true
autoconfigure: true
public: false
tags:
- { name: kernel.event_subscriber }

TWIG

Create a new File in your app-resource-directory: templates/OpenDxpNewsBundle/areas/news/edit_custom.html.twig and use common opendxp-methods to add your configuration:

<div class="t-row">
<div class="t-col-full">
<label>{{ 'news.<yourpropertyname>'|trans({}, 'admin') }}</label>
{{ opendxp_your_property_type('<yourproperty>', {
'types' : ['object', 'folder'],
'width' : '510px',
'height' : '150px',
...
}) }}
</div>
</div>

Modify Listing

Create a class that extends \OpenDxp\Bundle\NewsBundle\Model\Entry and add this method to use your new configuration-values

    /**
* @param DataObject\NewsEntry\Listing $listing
* @param array $settings
*/
protected static function modifyListing($listing, $settings = [])
{
# for example, add a condition
$listing->addConditionParam('<define your condition>');
}