Skip to content

Commit

Permalink
Update settings for SiteTree objects
Browse files Browse the repository at this point in the history
  • Loading branch information
amolswnz committed May 2, 2024
1 parent c5a5489 commit fce9812
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/Extensions/SearchServiceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ public function __construct(
$this->setBatchProcessor($batchProcessor);
}

/**
* General DataObject Search settings
*
* @param FieldList $fields
* @return void
*/
public function updateCMSFields(FieldList $fields): void
{
if (!$this->getConfiguration()->isEnabled()) {
if ($this->owner instanceof SiteTree || !$this->getConfiguration()->isEnabled()) {
return;
}

Expand All @@ -75,12 +81,28 @@ public function updateCMSFields(FieldList $fields): void
_t(self::class . '.LastIndexed', 'Last indexed in search')
);

if ($this->owner instanceof SiteTree) {
$fields->addFieldToTab('Root.Main', $searchIndexedField);
} else {
$fields->push($showInSearchField);
$fields->push($searchIndexedField);
$fields->push($showInSearchField);
$fields->push($searchIndexedField);
}

/**
* Specific settings for SiteTree
*
* @param FieldList $fields
* @return void
*/
public function updateSettingsFields(FieldList $fields): void
{
if (!$this->owner instanceof SiteTree || !$this->getConfiguration()->isEnabled()) {
return;
}

$searchIndexedField = ReadonlyField::create(
'SearchIndexed',
_t(self::class . '.LastIndexed', 'Last indexed in search')
);

$fields->insertAfter('ShowInSearch', $searchIndexedField);
}

/**
Expand Down

0 comments on commit fce9812

Please sign in to comment.