diff --git a/src/Models/Page.php b/src/Models/Page.php index 9983dcd..2487224 100644 --- a/src/Models/Page.php +++ b/src/Models/Page.php @@ -25,7 +25,8 @@ public function getRevisionOptions(): RevisionOptions 'image' => 'getImages', 'repeater' => 'getRepeater', ]) - ->registerCacheTagsToFlush(['cms_pages']); + ->registerCacheTagsToFlush(['cms_pages']) + ->setIndexable(true, ['page_title'], 'page_title'); } /** diff --git a/src/Traits/RevisionOptions.php b/src/Traits/RevisionOptions.php index 0ba25df..201154d 100644 --- a/src/Traits/RevisionOptions.php +++ b/src/Traits/RevisionOptions.php @@ -58,6 +58,13 @@ class RevisionOptions */ public $indexableKeys = []; + /** + * Key to save as title + * + * @var string + */ + public $titleKey = ''; + public static function create(): self { return new static(); @@ -100,10 +107,19 @@ public function registerCacheTagsToFlush(array $tags): self return $this; } - public function setIndexable(bool $searchable, array $indexableKeys = []): self + /** + * Undocumented function + * + * @param bool $searchable + * @param array $indexableKeys + * @param string $titleKey + * @return self + */ + public function setIndexable(bool $searchable, array $indexableKeys = [], string $titleKey = ''): self { $this->isIndexable = $searchable; $this->indexableKeys = $indexableKeys; + $this->titleKey = $titleKey; return $this; } diff --git a/tests/Page/PageTest.php b/tests/Page/PageTest.php index b24896e..1475b42 100644 --- a/tests/Page/PageTest.php +++ b/tests/Page/PageTest.php @@ -415,4 +415,22 @@ public function it_can_get_revision_options() $this->assertIsArray($tagsToFlush); $this->assertEquals('cms_pages', $tagsToFlush[0]); } + + /** @test **/ + public function it_can_get_indexable_keys_from_options() + { + // Arrange + $page = Page::factory()->create([ + 'revision' => 10, + ]); + $indexableKeys = $page->getRevisionOptions()->indexableKeys; + + // Act + + // Assert + $this->assertIsArray($indexableKeys); + $this->assertEquals('page_title', $indexableKeys[0]); + $this->assertEquals(true, $page->getRevisionOptions()->isIndexable); + $this->assertEquals('page_title', $page->getRevisionOptions()->titleKey); + } }