PHP | Problem -
/*************** SubteaserAdmin.php *************************/
<?php
class SubteaserAdmin extends ModelAdmin {
public static $managed_models = array(
'Subteaser'
);
static $url_segment = 'subteaser';
static $menu_title = 'Subteaser';
}
/*************** Subteaser.php *************************/
<?php
class Subteaser extends DataObject {
public static $db = array(
'Headline' => 'Varchar(255)',
'Text' => 'HTMLText',
'Link' => 'Text',
'Type' => 'Boolean',
'Description' => 'HTMLText'
);
public static $has_one = array(
'Image' => 'Image'
);
public static $belongs_many_many = array(
'myPage' => 'myPage'
);
public static $searchable_fields = array(
'Headline',
'Link',
'Type' => array(
'title'=>'Special?'
),
'Description'
);
//Fields to show in ModelAdmin table
public static $summary_fields = array(
'Headline' => 'Headline',
'Text' => 'Text',
'Link' => 'Link',
'Type' => 'Special (contains code?)',
'Image' => 'Image'
);
public function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField( 'Headline' ) );
$fields->push( new TextField( 'Text' ) );
$fields->push( new TextField( 'Link' ) );
return $fields;
}
public function getCMSValidator() {
$rule_Subteaser_OnlyFourSubteaser = new NetefxValidatorRuleFUNCTION("Subteaser",
"Please choose only 4 or less Subteasers.",
'error',
array('NetefxValidatorLibraryCheckbox',
'max_number_checkboxes_checked',
array( 'field' => 'Subteaser',
'max' => 4)
));
}
}
/*************** myPage.php *************************/
<?php
class myPage extends Page {
static $db = array(
);
static $has_one = array(
'moodPicture' => 'Image'
);
static $many_many = array(
'Subteaser' => 'Subteaser',
'Features' => 'Feature'
);
static $allowed_children = array('NewsHolder', 'ContestHolder', 'ThumbHolder', 'EventHolder');
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new ImageField('moodPicture', 'Moodbild', Null, Null, Null, 'Uploads/Moodbilder/'), 'Content');
$fields->removeFieldFromTab("Root.Content.Main","Content");
$Subteaser= DataObject::get('Subteaser');
if (!empty($Subteaser)) {
$map = $Subteaser->toDropdownMap('ID', 'Headline');
$fields->addFieldToTab('Root.Content.Subteaser',
new CheckboxSetField(
$name = "Subteaser",
$title = "Select Subteaser",
$source = $map
));
}
return $fields;
}
}
class myPage_Controller extends Page_Controller {
}
?>
28/06/2012 11:17am
PHP | Solution - Anonymous
Or try this first:
public function getCMSValidator() {
$rule_Text_required = new NetefxValidatorRuleREQUIRED ("Text", "You have to enter a text", "error");
$validator = new NetefxValidator($rule_Text_required);
return $validator;
}
28/06/2012 11:08am
PHP | Solution - lx-berlin
public function getCMSValidator() {
$rule_Subteaser_OnlyFourSubteaser = new NetefxValidatorRuleFUNCTION("Subteaser",
"Please choose only 4 or less Subteasers.",
'error',
array('NetefxValidatorLibraryCheckbox',
'max_number_checkboxes_checked',
array( 'field' => 'Subteaser',
'max' => 4)
));
$validator = new NetefxValidator($rule_Subteaser_OnlyFourSubteaser);
return $validator;
}