/** * Form used for defining the conversion form * @return {Form} Form to be used for configuring the conversion */ public function ConvertObjectForm() { //Reset the reading stage Versioned::reset(); $fields = new FieldList(CompositeField::create($convertModeField = new OptionsetField('ConvertMode', '', array('ReplacePage' => _t('KapostAdmin.REPLACES_AN_EXISTING_PAGE', '_This replaces an existing page'), 'NewPage' => _t('KapostAdmin.IS_NEW_PAGE', '_This is a new page')), 'NewPage'))->addExtraClass('kapostConvertLeftSide'), CompositeField::create($replacePageField = TreeDropdownField::create('ReplacePageID', _t('KapostAdmin.REPLACE_PAGE', '_Replace this page'), 'SiteTree')->addExtraClass('replace-page-id'), TreeDropdownField::create('ParentPageID', _t('KapostAdmin.USE_AS_PARENT', '_Use this page as the parent for the new page, leave empty for a top level page'), 'SiteTree')->addExtraClass('parent-page-id'))->addExtraClass('kapostConvertRightSide')); $actions = new FieldList(FormAction::create('doConvertObject', _t('KapostAdmin.CONTINUE_CONVERT', '_Continue'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'kapost-convert')); $validator = new RequiredFields('ConvertMode'); $form = new Form($this, 'ConvertObjectForm', $fields, $actions, $validator); $form->addExtraClass('KapostAdmin center')->setAttribute('data-layout-type', 'border')->setTemplate('KapostAdmin_ConvertForm'); //Handle pages to see if the page exists $convertToClass = $this->getDestinationClass(); if ($convertToClass !== false && ($convertToClass == 'SiteTree' || is_subclass_of($convertToClass, 'SiteTree'))) { $obj = SiteTree::get()->filter('KapostRefID', Convert::raw2sql($this->record->KapostRefID))->first(); if (!empty($obj) && $obj !== false && $obj->ID > 0) { $convertModeField->setValue('ReplacePage'); $replacePageField->setValue($obj->ID); $recordTitle = $this->record->Title; if (!empty($recordTitle) && $recordTitle != $obj->Title) { $urlFieldLabel = _t('KapostAdmin.TITLE_CHANGE_DETECT', '_The title differs from the page being replaced, it was "{wastitle}" and will be changed to "{newtitle}". Do you want to update the URL Segment?', array('wastitle' => $obj->Title, 'newtitle' => $recordTitle)); $fields->push(CheckboxField::create('UpdateURLSegment', $urlFieldLabel)->addExtraClass('urlsegmentcheck')->setAttribute('data-replace-id', $obj->ID)->setForm($form)->setDescription(_t('KapostAdmin.NEW_URL_SEGMENT', '_The new URL Segment will be or will be close to "{newsegment}"', array('newsegment' => $obj->generateURLSegment($recordTitle))))); } } } Requirements::css(KAPOST_DIR . '/css/KapostAdmin.css'); Requirements::add_i18n_javascript(KAPOST_DIR . '/javascript/lang/'); Requirements::javascript(KAPOST_DIR . '/javascript/KapostAdmin_convertPopup.js'); //Allow extensions to adjust the form $this->extend('updateConvertObjectForm', $form, $this->record); return $form; }
function setValue($value) { if ($value == '__custom__') { $value = isset($_REQUEST[$this->name . '_custom']) ? $_REQUEST[$this->name . '_custom'] : null; } if ($value) { parent::setValue($value); } }
public function testReadonlyField() { $sourceArray = array(0 => 'No', 1 => 'Yes'); $field = new OptionsetField('FeelingOk', 'are you feeling ok?', $sourceArray, 1); $field->setEmptyString('(Select one)'); $field->setValue(1); $readonlyField = $field->performReadonlyTransformation(); preg_match('/Yes/', $field->Field(), $matches); $this->assertEquals($matches[0], 'Yes'); }
/** * @param IRSVP $rsvp * @param IRSVPQuestionTemplate $question * @param IRSVPAnswer $answer * @return FormField */ public function build(IRSVP $rsvp, IRSVPQuestionTemplate $question, IRSVPAnswer $answer) { $options = array(); foreach ($question->Values()->sort('Order') as $val) { $options[$val->ID] = empty($val->Label) ? $val->Value : $val->Label; } $field = new OptionsetField($question->name(), $question->label(), $options); $default_value = $question->getDefaultValue(); if (!is_null($default_value) && $default_value->ID > 0) { $field->setValue($default_value->ID); } if ($question->isReadOnly()) { $field->setDisabled(true); } if ($question->isMandatory()) { $field->setAttribute('data-rule-required', 'true'); } if (!is_null($answer)) { $field->setValue($answer->value()); } $field->setTemplate('RSVPOptionSetField'); return $this->buildDependantRules($rsvp, $question, $field); }
public function setValue($value) { // Avoid setting blank as no if ($value === '' || $value === null) { return; } if ($value !== self::VALUE_YES && $value !== self::VALUE_NO) { if ((int) $value) { $value = self::VALUE_YES; } else { $value = self::VALUE_NO; } } parent::setValue($value); }
/** * Load a value into this CheckboxSetField */ public function setValue($value, $obj = null) { // If we're not passed a value directly, we can look for it in a relation method on the object passed as a // second arg if (!$value && $obj && $obj instanceof DataObject && $obj->hasMethod($this->name)) { $funcName = $this->name; $value = $obj->{$funcName}()->getIDList(); } parent::setValue($value, $obj); return $this; }
public function setValue($value) { // Extract custom option from postback if (is_array($value)) { if (empty($value['Options'])) { $value = ''; } elseif ($value['Options'] === self::CUSTOM_OPTION) { $value = $value['Custom']; } else { $value = $value['Options']; } } return parent::setValue($value); }
public function setValue($value, $obj = null) { if ($this->fieldType == 'CheckboxSetField') { CheckboxSetField::setValue($value, $obj); } else { parent::setValue($value); } }
/** * Load a value into this CheckboxSetField */ function setValue($value, $obj = null) { // If we're not passed a value directly, we can look for it in a relation method on the object passed as a second arg if (!$value && $obj && $obj instanceof DataObject && $obj->hasMethod($this->name)) { $funcName = $this->name; $selected = $obj->{$funcName}(); $value = $selected->toDropdownMap('ID', 'ID'); } parent::setValue($value, $obj); }