How to change default select for page holder in CMS?
Problem is as follows: client has some articles that will have three custom statuses as HouseStatus (sold, in sale and booked). If client changes article status to one of those, the article must “move” to corresponding article holder. I found the extension suggestion here, but it wont load. Any ideas/suggestions?
Just FYI - it looks like there’s a logical problem in the final code you posted. The first if block will only be executed if $this->HouseStatus == 'Sold', so the first two cases in your switch block are redundant, and the last will fire every time. If you take out the && $this->HouseStatus == 'Sold' part from your if block I think it will work as intended.
Thanks for inputs! Sadly I posted the solution before I “fixed” it even more. The end code I went with differs a lot from the code I posted (including get id, setParents part and logic bug for sold part). But cause I’m newbie, Admins review my posts and as long as the posts are not reviewed, I cannot change them
Here is the actual code then:
class ArticlePage extends Page {
static $allowed_children = 'none';
...
public function getCMSFields() {
...
}
public function onBeforeWrite() {
if ($this->isChanged('HouseStatus')) {
switch ($this->HouseStatus){
case "Sale":
//$parentPage = Page::get() -> filter('URLSegemnt', 'for-sale') -> first();
$this -> setParent('111');
break;
case "Booked":
//$parentPage = Page::get() -> filter('URLSegemnt', 'booked') -> first();
$this -> setParent('112');
break;
case "Sold":
//$parentPage = Page::get() -> filter('URLSegemnt', 'sold-out') -> first();
$this -> setParent('113');
break;
};
//$this->setParent($parentPage);
}
parent::onBeforeWrite();
}
}
Basically as You can see, I did both solution (whichever is needed in the future).