-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for virtual pages, pulling content from the origina…
…l source.
- Loading branch information
Showing
4 changed files
with
188 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Wilr\SilverStripe\Algolia\Extensions; | ||
|
||
use SilverStripe\Core\Injector\Injector; | ||
use SilverStripe\ORM\ArrayList; | ||
use SilverStripe\ORM\Map; | ||
use SilverStripe\Subsites\Model\Subsite; | ||
use Wilr\SilverStripe\Algolia\Service\AlgoliaIndexer; | ||
|
||
class SubsitesVirtualPageExtension extends \SilverStripe\ORM\DataExtension | ||
{ | ||
public function exportObjectToAlgolia($toIndex) | ||
{ | ||
$attributes = new Map(ArrayList::create()); | ||
|
||
foreach ($toIndex as $k => $v) { | ||
if ($k === 'objectClassName') { | ||
continue; | ||
} | ||
|
||
$attributes->push($k, $v); | ||
} | ||
|
||
/** @var AlgoliaIndexer */ | ||
$indexer = Injector::inst()->get(AlgoliaIndexer::class); | ||
$owner = $this->owner; | ||
|
||
// get original object | ||
$result = Subsite::withDisabledSubsiteFilter(function () use ($owner, $attributes, $indexer) { | ||
$originalObject = $owner->CopyContentFrom(); | ||
|
||
if (!$originalObject) { | ||
return $attributes; | ||
} | ||
|
||
$attributes->push('objectClassName', $originalObject->ClassName); | ||
$specs = $originalObject->config()->get('algolia_index_fields'); | ||
$attributes = $indexer->addSpecsToAttributes($originalObject, $attributes, $specs); | ||
|
||
$originalObject->invokeWithExtensions('updateAlgoliaAttributes', $attributes); | ||
|
||
return $attributes; | ||
}); | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Wilr\SilverStripe\Algolia\Extensions; | ||
|
||
use SilverStripe\Core\Injector\Injector; | ||
use SilverStripe\ORM\ArrayList; | ||
use SilverStripe\ORM\Map; | ||
use Wilr\SilverStripe\Algolia\Service\AlgoliaIndexer; | ||
|
||
class VirtualPageExtension extends \SilverStripe\ORM\DataExtension | ||
{ | ||
public function exportObjectToAlgolia($toIndex) | ||
{ | ||
$attributes = new Map(ArrayList::create()); | ||
|
||
foreach ($toIndex as $k => $v) { | ||
if ($k === 'objectClassName') { | ||
continue; | ||
} | ||
|
||
$attributes->push($k, $v); | ||
} | ||
|
||
/** @var AlgoliaIndexer */ | ||
$indexer = Injector::inst()->get(AlgoliaIndexer::class); | ||
$owner = $this->owner; | ||
|
||
// get original object | ||
$originalObject = $owner->CopyContentFrom(); | ||
|
||
if (!$originalObject) { | ||
return $attributes; | ||
} | ||
|
||
$attributes->push('objectClassName', $originalObject->ClassName); | ||
$specs = $originalObject->config()->get('algolia_index_fields'); | ||
$attributes = $indexer->addSpecsToAttributes($originalObject, $attributes, $specs); | ||
|
||
$originalObject->invokeWithExtensions('updateAlgoliaAttributes', $attributes); | ||
|
||
return $attributes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters