Skip to content

Commit

Permalink
[5.x] Support search_index tag supplemental data (#312)
Browse files Browse the repository at this point in the history
* Support search_index tag supplemental data

* Supplement method should return $this

* 🍺

---------

Co-authored-by: Duncan McClean <duncan@duncanmcclean.com>
Co-authored-by: Duncan McClean <19637309+duncanmcclean@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 4, 2023
1 parent d085f72 commit 156d8d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/Data/AugmentedModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ class AugmentedModel extends AbstractAugmented

protected $resource;

protected $supplements = [];

public function __construct($model)
{
$this->data = $model;
$this->resource = Runway::findResourceByModel($model);
}

public function supplement(array $data)
{
$this->supplements = $data;

return $this;
}

public function keys()
{
return collect()
Expand Down Expand Up @@ -94,6 +103,6 @@ protected function blueprintFields()

protected function getFromData($handle)
{
return $this->data->$handle;
return $this->supplements[$handle] ?? $this->data->$handle;
}
}
6 changes: 4 additions & 2 deletions src/Search/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
use Statamic\Contracts\Query\ContainsQueryableValues;
use Statamic\Contracts\Search\Result;
use Statamic\Contracts\Search\Searchable as Contract;
use Statamic\Data\ContainsSupplementalData;
use Statamic\Data\HasAugmentedInstance;
use Statamic\Facades\Site;
use Statamic\Search\Result as ResultInstance;

class Searchable implements Contract, ContainsQueryableValues, Augmentable
{
use HasAugmentedInstance;
use HasAugmentedInstance, ContainsSupplementalData;

protected $model;

Expand Down Expand Up @@ -76,6 +77,7 @@ public function getCpSearchResultBadge()

public function newAugmentedInstance(): Augmented
{
return new AugmentedModel($this->model);
return (new AugmentedModel($this->model))
->supplement($this->supplements());
}
}

0 comments on commit 156d8d4

Please sign in to comment.