21489 Posts in 5783 Topics by 2622 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 309 Views |
-
If statement in getCMSFields

1 September 2012 at 2:25am
I apologise if this is really obvious and a stupid question but I'm a little stumped. I'm trying to add a field that is only visible on one page so I am using an if statement in the getCMSFields function of my page.
My question is is this even possible? Will it be called, etc? The reason I ask is that my if statement doesn't work unless I change getCMSFields to getCMSFields_forPopup which causes a whole new set of problems.
Please help!
Thanks in advance.
P.S. I'm using SilverStripe 2.4.7.
if ($this->ClassName == 'Movies') {
$movies= DataObject::get('Movie');if (! empty($stores)) {
$map = $movies->toDropdownMap('ID', 'Name');
$checkBox = new CheckboxSetField(
$name = "Moviess",
$title = "Select Movies",
$source = $map
);$fieldset->push($checkBox);
}
} -
Re: If statement in getCMSFields

2 September 2012 at 2:03pm
You should be able to use an if perfectly fine. Though it would be better design to move the functionality to your Movies.php class.
<?php
class Movies extends Page {
..function getCMSFields() {
$fields = parent::getCMSFields();
$movies= DataObject::get('Movie');if (! empty($movies)) {
$map = $movies->toDropdownMap('ID', 'Name');
$fieldset->push(new CheckboxSetField( "Movies", "Select Movies", $map));
}return $fields;
} -
Re: If statement in getCMSFields

3 September 2012 at 9:44pm Last edited: 3 September 2012 9:45pm
Thanks for your reply willr. I am using a Dataobject with a dataobjectmanager in movies. Can I still use this method? I'm relatively new to SilverStripe so my knowledge is limited but I can't see how it'll work that way.
I'm using 2.4.7, I just realised I never specified that earlier.
-
Re: If statement in getCMSFields

4 September 2012 at 5:54pm
You should be able to use the same setup whether you have dataobjects or pages. Though getCMSFields may be getCMSFields_forPopup if you're using the popup to edit content.
-
Re: If statement in getCMSFields

6 September 2012 at 8:13pm Last edited: 6 September 2012 8:39pm
Ok that makes sense. Thank you. It's still not working exactly as I want it to but I have a better understanding of what is going on. I think my confusion lies with DataObjectManager though as it creates the popup for editing the data and is created within getCMSFields of Movies. If I understand correctly then I need to use getCMSFields_ForPopup in Movies instead?
| 309 Views | ||
|
Page:
1
|
Go to Top |


