I have an extension that sets up search fields like this:
public function onBeforeWrite(){
parent::onBeforeWrite();
$this->getOwner()->SearchContent = $this->collateSearchContent();
}
Which works ok, except only on new or updated pages. I want to loop through the SiteTree and save the SearchContent for each.
In my task I do this:
foreach (SiteTree::get() as $item) {
$the_text = $item->collateSearchContent();
# Previously: $item->getOwner()->SearchContent = $the_text;
$item->SearchContent = $the_text;
$item->write();
}
I get the error:
Caught exception: Object->__call(): the method 'collateSearchContent' does not exist on 'Page'
So, nearly there. But it's not using the SiteTree object to find the method. How do I access the sitetree object?
$this->getOwner()works in the first scenario because$thisis an instance ofExtension, and$this->getOwner()returns aSiteTreerecord.In the second scenario,
$itemis theSiteTreerecord, sogetOwner()isn't needed.What's more,
save()is not going to work, because that method doesn't exist onSiteTree(see API docs).