Pipelines
While Dexter does handle a lot of stuff out of the box, if you are in need of some custom behaviors, or modification of data that is indexed, making a new pipeline is the answer. For this you will need some PHP knowledge. Pipelines must be namespaced classes. You can include additional pipelines by adding them to your config file:
$config['dexter'] = [
'pipelines' => [
\BoldMinded\DexterPipelines\Pipeline\ExamplePipeline::class,
\Acme\Something\MyPipeline::class,
]
];
To make it easier to include custom pipelines the dexter_pipelines
add-on is included with Dexter. Since you will be adding files unique to your site to this add-on, do not update it when you update Dexter with a new version.
There may be some pipelines available in Dexter that are not enabled by default, such as the CommentsPipeline. You can view a list of all the available pipelines in the Service/Pipeline
folder. To enable the CommentsPipeline or any other one simply add it to the $config
array.
$config['dexter'] = [
'pipelines' => [
\BoldMinded\Dexter\Pipeline\CommentsPipeline::class,
]
];
Dexter uses the League\Pipeline package, and as such all pipelines need to follow the same structure and method signatures. Below is an example of the CategoryPipeline from Dexter's codebase. The basic concept is a item or collection of data is passed through a series of classes, each one manipulating the data if necessary. The order in which the pipes are declared matters. In Dexter's case, we have a simple array of entry data. Some pipes append new data to the array, and others might manipuate existing data. At the end of the pipeline we end up with an array that ends up getting encoded into json and indexed in Algolia or Meilisearch.
<?php
namespace BoldMinded\Dexter\Service\Pipeline;
use BoldMinded\Dexter\Service\Config;
use ExpressionEngine\Model\Category\Category;
use ExpressionEngine\Model\Channel\ChannelEntry;
class CategoryPipeline
{
/**
* @var ChannelEntry
*/
private $channelEntry;
/**
* @var Config
*/
private $config;
/**
* @param ChannelEntry $channelEntry
* @param Config $config
*/
public function __construct(ChannelEntry $channelEntry, Config $config)
{
$this->channelEntry = $channelEntry;
$this->config = $config;
}
/**
* @param array $values
* @return array
*/
public function __invoke(array $values): array
{
if (empty($values)) {
return [];
}
$categories = $this->config->get('categories');
if (empty($categories)) {
return $values;
}
$values['categories'] = $this->channelEntry->Categories
->filter('group_id', 'IN', $categories)
->pluck('cat_name');
return $values;
}
}
Last updated
Was this helpful?