Skip to content

Commit

Permalink
FIX Get anchor links from elemental pages
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 29, 2021
1 parent 6fc5c4c commit 1e5fb35
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Extensions/ElementalPageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace DNADesign\Elemental\Extensions;

use DNADesign\Elemental\Models\ElementalArea;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\View\Parsers\HTML4Value;
use SilverStripe\View\SSViewer;
Expand Down Expand Up @@ -31,6 +32,25 @@ class ElementalPageExtension extends ElementalAreasExtension
* @return string
*/
public function getElementsForSearch()
{
return strip_tags($this->createHtml());
}

/**
* @param array $anchors
*
* @see SiteTree::getAnchorsOnPage()
*/
public function updateAnchorsOnPage(array &$anchors): void
{
if (!($this->owner instanceof SiteTree)) {
return;
}
$content = $this->createHtml();
$anchors = array_merge($anchors, $this->owner->getAnchorsInContent($content));
}

private function createHtml()
{
$oldThemes = SSViewer::get_themes();
SSViewer::set_themes(SSViewer::config()->get('themes'));
Expand All @@ -43,7 +63,7 @@ public function getElementsForSearch()
/** @var ElementalArea $area */
$area = $this->owner->$key();
if ($area) {
$output[] = strip_tags($area->forTemplate());
$output[] = $area->forTemplate();
}
}
} finally {
Expand Down

0 comments on commit 1e5fb35

Please sign in to comment.