Why do you have it extending ImageWidget? It's a subclass of DropdownField. Use the code as I gave it to you, and add the class anywhere in your ImageWidget.php file.
Then you can add new SimpleTreeDropdownField to your fieldset.
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Why do you have it extending ImageWidget? It's a subclass of DropdownField. Use the code as I gave it to you, and add the class anywhere in your ImageWidget.php file.
Then you can add new SimpleTreeDropdownField to your fieldset.
UncleCheese, thanks very much for the workaround class. I especially like the way you can just change the name from TreeDropdownField to SimpleTreeDropdownField in the fieldset and it works.
I too am using SimpleTreeDropdownField in getCMSFields_forPopup() and it works fine (thanks as always @UC). Question, though, in my DataObjectManager, I'd like to get the Title of the selected page in the SiteTree to display instead of the ID. In my DataObject, I've got:
public static $has_one = array(
"LinkedPage" => "SiteTree"
);
.....
public static $field_names = array(
"Title" => "Title",
"PageName" => "Link to Page",
"Content" => "Content"
);
.....
public function PageName() {
$Page = DataObject::get_by_id("SiteTree", $this->LinkedPageID);
return $Page->Title;
}
But obviously I'm getting an "Unknown column 'PageName' in 'field list'" when I click on the page in the CMS. Any idea how I can accomplish what I want here?
Thanks again,
Garrett
I've found where is the problem in using the TreeDropDownField in Widgets (in SS 2.4.7), and I have a simple workaround for that.
The problem is that the method Form::handleField() is not able to find and return the field to the ajax call that is thrown when you click on the dropdown.
Since, in cms/javascript/WidgetAreaEditor.js the name of dropdown fields that are in widgets are overwritten with the string "Widget_TDF_Endpoint", it suffices then to modify the sapphire/forms/Form.php and add this few lines to the handleField method (those between START_MOD and END_MOD):
function handleField($request) {
$field = $this->dataFieldByName($request->param('FieldName'));
if($field) {
return $field;
} else {
//START_MOD: TreeDropdownField in Widgets
$fieldName = $request->param('FieldName');
if ($fieldName == 'Widget_TDF_Endpoint') {
return new TreeDropdownField($fieldName, null, 'SiteTree');
}
//END_MOD
// falling back to fieldByName, e.g. for getting tabs
return $this->Fields()->fieldByName($request->param('FieldName'));
}
}
I hope this helps.