Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

sub classing and overriding function - basic problem

Go to End



Community Member, 24 Posts

27 September 2010 at 3:08am

This shouldnt be a problem to solve for experienced php codes, which I am not. I will welcome help and guidence.

The Thing:
I am subclassing SelectionGroup.php with MyFunc.php ...
In SelectionGroup.php is a function FieldSet() ...
I want to add one line of code into it, but left all the stuff doing its work.. the line I want to add is $item->addExtraClass('selected');
all relevant code also on pastie:

function FieldSet() {
		$items = parent::FieldSet()->toArray();

		$count = 0;
		$firstSelected = $checked ="";
		foreach($items as $key => $item) {
			if(strpos($key,'//') !== false) {
				list($key,$title) = explode('//', $key,2);
			} else {
				$title = $key;
			if($this->value == $key) {
				$firstSelected = " class=\"selected\"";
				$checked = " checked=\"checked\"";
			$itemID = $this->ID() . '_' . (++$count);
			$extra = array(
				"RadioButton" => "<input class=\"selector\" type=\"radio\" id=\"$itemID\" name=\"$this->name\" value=\"$key\"$checked />",
				"RadioLabel" => "<label for=\"$itemID\">$title</label>",
				"Selected" => $firstSelected,
			if(is_object($item)) $newItems[] = $item->customise($extra);
			else $newItems[] = new ArrayData($extra);

			$firstSelected = $checked ="";			
		return new DataObjectSet($newItems);

/// I want to edit section 
if($this->value == $key) {
		$firstSelected = " class=\"selected\"";
		$checked = " checked=\"checked\"";
// adding my line
if($this->value == $key) {
		$firstSelected = " class=\"selected\"";
		$checked = " checked=\"checked\"";

the class is added on the right place when I edit the core file SelectionGroup.php.
But when I copy the function to MyFunc.php, my label and other code disapear, as it will be working with other set of data.

So if anyone can drop the code of the FieldSet() that should be in MyFunc.php for it to work same as in SelectionGroup.php. that would be awesome..
Even better would be if you can also enlighten me what is going behind the scenes, and why it wont work, and / or point me to a solution for checking the selected radio button in the __constructor of MyFunc.php

Thank you all in advance.