1. Go to this page and download the library: Download wilr/silverstripe-algolia library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\Map;
class MyPage extends Page {
public function exportObjectToAlgolia($data)
{
$data = array_merge($data, [
'MyCustomField' => $this->MyCustomField()
]);
$map = new Map(ArrayList::create());
foreach ($data as $k => $v) {
$map->push($k, $v);
}
return $map;
}
}
public function updateAlgoliaRelationshipAttributes(\SilverStripe\ORM\Map $attributes, $related)
{
$attributes->push('CategoryName', $related->CategoryName);
}
public function canIndexInAlgolia(): bool
{
return ($this->Expired) ? false : true;
}