AlgoliaIndexer for DataObject requires object|string but receiving an array

Silverstripe Version: 10.0.0

I am using the SilverStripe Algolia Module and it works well except for an error I am receiving when I try to call $this->indexInAlgolia() after creating a ‘Provider’ dataobject which is not using the versioning extension.

I have added the following method to my dataobject to manually add the object to the Algolia index when creating/updating as it said in the instructions:

public function onAfterWrite()
        if ($this->canIndexInAlgolia()) {

When creating a new Provider I receive the following error:

method_exists(): Argument #1 ($object_or_class) must be of type object|string, array given at /var/www/localhost/htdocs/vendor/wilr/silverstripe-algolia/src/Service/AlgoliaIndexer.php:66

I can temporarily fix the error by hacking the Wilr\SilverStripe\Algolia\Service\AlgoliaIndexer indexItem() method code to check if the result is already an array (which it appears to be):

if (!is_array($fields)) {
    if (method_exists($fields, 'toArray')) {
        $fields = $fields->toArray();

How should I have added the manual index to my dataobject to avoid this error? I can’t find any examples of how to do this :slight_smile: