PHP | Problem - modelAdmin/ManyManyDataObjectManager Bug
/* Subteaser.php */
<?php
class Subteaser extends DataObject {
static $extensions = array(
'Translatable'
);
public static $db = array(
'Headline' => 'Varchar(255)',
'Text' => 'HTMLText',
'LinkExtern' => 'Varchar(255)',
'Description' => 'Text',
'containsHTML' => 'Boolean'
);
public static $has_one = array(
'LinkIntern' => 'Page',
'Image' => 'Image'
);
public static $belongs_many_many = array(
'myvPage' => 'myPage'
);
public static $searchable_fields = array(
'Headline',
'Text',
'Description'
);
public static $summary_fields = array(
'Description' => 'Description'/*,
'Headline' => 'Headline'*/
);
public function getCMSFields() {
$fields = parent::getCMSFields();
Translatable::set_reading_lang(Translatable::get_current_locale());
$fields->replaceField('Text',new HtmlEditorField( 'Text', 'Text (content)', 15 ));
$fields->removeByName('containsHTML');
$fields->removeByName('LinkExtern');
$fields->removeByName('LinkIntern');
$fields->removeByName('LinkInternID');
$myPages = DataObject::get("Page", "", "", "", "");
$fields->addFieldToTab('Root.Main', new FieldGroup( new DropDownField('LinkInternID', 'Choose one', $myPages->map('ID', 'Title', '(Select one)', true), 'LinkInternID'),
new TextField('LinkExtern', 'Link (extern)' )
));
return $fields;
}
/* for ->map(): we generate a nice-looking string which is far more
descriptive than just the title (which we don't even have to
specify, as long as there's the description) */
function getMyObjectOptions() {
if($Pages = DataObject::get('Subteaser')) {
return $Pages->map('ID', 'DropdownSummary', 'Select one');
} else {
return array('No Objects found');
}
}
function DropdownSummary() {
$String = $this->Headline . ' (' . $this->Description . ')';
return $String;
}
}
/* myPage.php */
<?php
class myPage extends Page {
static $db = array(
);
static $has_one = array(
'moodPicture' => 'Image'
);
static $many_many = array(
'Subteaser' => 'Subteaser',
'Features' => 'Feature'
);
function getCMSFields() {
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Subteaser", new ManyManyDataObjectManager(
$this,
'Subteaser',
'Subteaser',
array('Headline' => 'Headline', 'Text' => 'Text', 'Description' => 'Description'), //with Text the page won't render properly
'getCMSFields'
));
return $f;
}
}
class myPage_Controller extends Page_Controller {
}
?>
04/07/2012 1:07pm
PHP | Comment - LePhil
Submitted to http://open.silverstripe.org/ticket/7620