public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName(array('SortOrder', 'Pic', 'UID')); $fields->addFieldsToTab('Root.Main', array(CheckboxField::create('Visible', _t('FacebookPost.VISIBLE', 'Is visible?')), DatetimeField_Readonly::create('Date', _t('FacebookPost.DATE', 'Posted on')), NumericField_Readonly::create('Likes', _t('FacebookPost.LIKES', 'Likes')), HtmlEditorField::create('Message', _t('FacebookPost.MESSAGE', 'Text'))->setRows(10))); return $fields; }
/** * Custimize the form fields to edit this S3 File * @return FieldList Form fields to edit this S3 File in the CMS */ public function getCMSFields() { $fields = parent::getCMSFields(); // Hide those fields because those values are not useful for standard users. $fields->removeByName('Location'); $fields->removeByName('Region'); $fields->removeByName('Bucket'); $fields->removeByName('Key'); $fields->removeByName('ETag'); $fields->removeByName('Size'); // Add a human friendly readonly size field $fields->addFieldToTab('Root.Main', ReadonlyField::create('FakeSize', 'Size', $this->SizeForHuman)); // Display a few usefull bits of data in readonly mod. $fields->addFieldToTab('Root.Main', ReadonlyField::create('Type', 'Type')); $fields->addFieldToTab('Root.Main', DatetimeField_Readonly::create('LastModified', 'Last Modified')); return $fields; }
function performReadonlyTransformation() { $field = new DatetimeField_Readonly($this->name, $this->title, $this->dataValue()); $field->setForm($this->form); return $field; }
function __construct($controller, $name, $article = null, bool $is_manager, $use_actions = true) { $IDField = new HiddenField('newsID'); //madatory fields $HeadlineField = new TextField('headline', 'Headline (150 character max)', '', $maxLength = 150); $HeadlineField->addExtraClass('headline'); $SummaryField = new HtmlEditorField('summary', 'Summary (300 character max)'); $SummaryField->addExtraClass('summary'); $SummaryField->setAttribute('max_chars', 300); $CityField = new TextField('city', 'City'); $StateField = new TextField('state', 'State'); $CountryField = new CountryDropdownField('country', 'Country'); $TagsField = new TextField('tags', 'Tags'); $DateEmbargoField = new TextField('date_embargo', 'Desired release date/time: Time zone is Central Time. Please ensure your release date is in Central Time (<a target="_blank" href="http://www.timeanddate.com/worldclock/converter.html">time converter</a>)'); $DateEmbargoField->addExtraClass('datefield'); if ($is_manager) { $DateExpireField = new TextField('date_expire', 'Expire Date'); $DateExpireField->addExtraClass('datefield'); } $UpdatedField = new DatetimeField_Readonly('date_updated', 'Last Updated'); //$UpdatedField->addExtraClass('inline'); //optional fields $BodyField = new HtmlEditorField('body', 'Body'); $LinkField = new TextField('link', 'Link'); $DocumentField = new CustomUploadField('Document', 'Document'); $DocumentField->addExtraClass('hidden'); $DocumentField->setCanAttachExisting(false); $DocumentField->setAllowedMaxFileNumber(1); $DocumentField->setAllowedFileCategories('doc'); $DocumentField->setTemplateFileButtons('CustomUploadField_FrontEndFIleButtons'); $DocumentField->setFolderName('news-documents'); $sizeMB = 1; // 1 MB $size = $sizeMB * 1024 * 1024; // 1 MB in bytes $DocumentField->getValidator()->setAllowedMaxFileSize($size); $DocumentField->setCanPreviewFolder(false); // Don't show target filesystem folder on upload field $DocumentField->setRecordClass('File'); $ImageField = new CustomUploadField('Image', 'Image (Max size 2Mb - Suggested size 300x250px)'); $ImageField->setCanAttachExisting(false); $ImageField->setAllowedMaxFileNumber(1); $ImageField->setAllowedFileCategories('image'); $ImageField->setTemplateFileButtons('CustomUploadField_FrontEndFIleButtons'); $ImageField->setFolderName('news-images'); $ImageField->setRecordClass('BetterImage'); $ImageField->getUpload()->setReplaceFile(false); $ImageField->setOverwriteWarning(false); $sizeMB = 2; // 2 MB $size = $sizeMB * 1024 * 1024; // 2 MB in bytes $ImageField->getValidator()->setAllowedMaxFileSize($size); $ImageField->setCanPreviewFolder(false); // Don't show target filesystem folder on upload field if ($is_manager) { $IsLandscapeField = new CheckboxField('is_landscape', 'Is Banner? (landscape image)'); $IsLandscapeField->addExtraClass('is_landscape'); } if ($article) { $IDField->setValue($article->ID); $HeadlineField->setValue($article->Headline); $SummaryField->setValue($article->Summary); $CityField->setValue($article->City); $StateField->setValue($article->State); $CountryField->setValue($article->Country); $TagsField->setValue($article->getTagsCSV()); if ($article->DateEmbargo) { $DateEmbargoField->setValue(date('m/d/Y g:i a', strtotime($article->DateEmbargo))); } else { $DateEmbargoField->setValue(gmdate('m/d/Y g:i a')); } $UpdatedField->setValue($article->LastEdited); $BodyField->setValue($article->Body); $LinkField->setValue($article->Link); if ($article->DateExpire) { $DateExpireField->setValue(date('m/d/Y g:i a', strtotime($article->DateExpire))); } $IsLandscapeField->setValue($article->IsLandscape); //submitter read only $SubmitterFirstNameField = new ReadonlyField('submitter_first_name', 'First Name'); $SubmitterLastNameField = new ReadonlyField('submitter_last_name', 'Last Name'); $SubmitterEmailField = new ReadonlyField('submitter_email', 'Email'); $SubmitterCompanyField = new ReadonlyField('submitter_company', 'Company'); $SubmitterPhoneField = new ReadonlyField('submitter_phone', 'Phone'); $SubmitterFirstNameField->setValue($article->getSubmitter()->FirstName); $SubmitterLastNameField->setValue($article->getSubmitter()->LastName); $SubmitterEmailField->setValue($article->getSubmitter()->Email); $SubmitterCompanyField->setValue($article->getSubmitter()->Company); $SubmitterPhoneField->setValue($article->getSubmitter()->Phone); } else { // submitter fields $SubmitterFirstNameField = new TextField('submitter_first_name', 'First Name'); $SubmitterLastNameField = new TextField('submitter_last_name', 'Last Name'); $SubmitterEmailField = new TextField('submitter_email', 'Email'); $SubmitterCompanyField = new TextField('submitter_company', 'Company'); $SubmitterPhoneField = new TextField('submitter_phone', 'Phone'); $LinkField->setValue('http://'); } $fields = new FieldList($IDField, $HeadlineField, $SummaryField, $CityField, $StateField, $CountryField, $TagsField, $DateEmbargoField); if ($is_manager) { $fields->push($DateExpireField); $fields->push($UpdatedField); } $fields->push(new LiteralField('clear', '<div class="clear"></div>')); $fields->push($BodyField); $fields->push($LinkField); $fields->push($DocumentField); if ($article) { $image = $article->Image(); $document = $article->Document(); if ($document->exists()) { $fields->push(new LiteralField('image_preview', $document->CMSThumbnail())); } $fields->push(new LiteralField('break', '<br/>')); $fields->push($ImageField); if ($image->exists()) { $ImageField->setValue(null, $article); } } else { $fields->push(new LiteralField('break', '<br/>')); $fields->push($ImageField); } if ($is_manager) { $fields->push($IsLandscapeField); $fields->push(new LiteralField('break', '<br/>')); } $fields->push(new LiteralField('break', '<br/><hr/>')); $fields->push(new LiteralField('title', '<h2>Submitter</h2>')); $fields->push($SubmitterFirstNameField); $fields->push($SubmitterLastNameField); $fields->push($SubmitterEmailField); $fields->push($SubmitterCompanyField); $fields->push($SubmitterPhoneField); // Create action $actions = new FieldList(); $actions->push(new FormAction('saveNewsArticle', 'Save')); $this->addExtraClass('news-registration-form'); parent::__construct($controller, $name, $fields, $actions, $validator = null); }
/** * Gets the form used for viewing snippets * @param {int} $id ID of the record to fetch * @param {FieldList} $fields Fields to use * @return {Form} Form to be used */ public function getEditForm($id = null, $fields = null) { if (!$id) { $id = $this->currentPageID(); } $form = parent::getEditForm($id); $record = $this->getRecord($id); if ($record && !$record->canView()) { return Security::permissionFailure($this); } if (!$fields) { $fields = $form->Fields(); } $actions = $form->Actions(); if ($record) { $fields->push($idField = new HiddenField("ID", false, $id)); $versions = $record->Versions()->filter('ID:not', $record->CurrentVersionID)->Map('ID', 'Created'); $actions = new FieldList(new FormAction('doCopy', _t('CodeBank.COPY', '_Copy')), new FormAction('doEditRedirect', _t('CodeBank.EDIT', '_Edit')), new FormAction('doExport', _t('CodeBank.EXPORT', '_Export')), new FormAction('doPrint', _t('CodeBank.PRINT', '_Print')), new LabelField('Revision', _t('CodeBank.REVISION', '_Revision') . ': '), DropdownField::create('RevisionID', '', $versions, $this->urlParams['OtherID'])->setEmptyString('{' . _t('CodeBank.CURRENT_REVISION', '_Current Revision') . '}')->setDisabled($record->Versions()->Count() <= 1)->addExtraClass('no-change-track'), FormAction::create('compareRevision', _t('CodeBank.COMPARE_WITH_CURRENT', '_Compare with Current'))->setDisabled($record->Versions()->Count() <= 1 || empty($this->urlParams['OtherID']) || !is_numeric($this->urlParams['OtherID']))); // Use <button> to allow full jQuery UI styling $actionsFlattened = $actions->dataFields(); if ($actionsFlattened) { foreach ($actionsFlattened as $action) { if ($action instanceof FormAction) { $action->setUseButtonTag(true); } } } if ($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); } else { $validator = new RequiredFields(); } if ($record->Package() && $record->Package() !== false && $record->Package()->ID != 0) { $package = new ArrayList(array($record->Package())); } else { $package = null; } $fields->insertBefore($fields->dataFieldByName('Title'), 'LanguageID'); $fields->replaceField('PackageID', new PackageViewField('PackageID', _t('Snippet.PACKAGE', '_Package'), $package, $record->ID)); $fields->replaceField('Text', HighlightedContentField::create('SnippetText', _t('Snippet.CODE', '_Code'), $record->Language()->HighlightCode)->setForm($form)); $fields->replaceField('Tags', new TagsViewField('Tags', _t('Snippet.TAGS_COLUMN', '_Tags'))); $fields->addFieldToTab('Root.Main', $creator = ReadonlyField::create('CreatorName', _t('CodeBank.CREATOR', '_Creator'), $record->Creator() && $record->Creator()->ID > 0 ? '<a href="' . $this->Link() . '?creator=' . $record->CreatorID . '">' . $record->Creator()->Name . '</a>' : _t('CodeBank.UNKNOWN_USER', '_Unknown User'))->setForm($form)); $creator->dontEscape = true; $fields->addFieldToTab('Root.Main', ReadonlyField::create('LanguageName', _t('CodeBank.LANGUAGE', '_Language'), $record->Language()->Name)->setForm($form)); $fields->addFieldToTab('Root.Main', DatetimeField_Readonly::create('LastModified', _t('CodeBank.LAST_MODIFIED', '_Last Modified'), $record->CurrentVersion->LastEdited)->setForm($form)); $fields->addFieldToTab('Root.Main', ReadonlyField::create('LastEditorName', _t('CodeBank.LAST_EDITED_BY', '_Last Edited By'), $record->LastEditor() && $record->LastEditor()->ID > 0 ? $record->LastEditor()->Name : _t('CodeBank.UNKNOWN_USER', '_Unknown User'))->setForm($form)); $fields->addFieldToTab('Root.Main', ReadonlyField::create('SnippetID', _t('CodeBank.ID', '_ID'), $record->ID)); $fields->addFieldToTab('Root.Main', ReadonlyField::create('CurrentVersionID', _t('CodeBank.VERSION', '_Version'))); $fields->push(new HiddenField('ID', 'ID')); $form = new Form($this, 'EditForm', $fields, $actions, $validator); $form->loadDataFrom($record); $form->disableDefaultAction(); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->addExtraClass('center ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); //Swap content for version text if (!empty($this->urlParams['OtherID']) && is_numeric($this->urlParams['OtherID'])) { $version = $record->Version(intval($this->urlParams['OtherID'])); if (!empty($version) && $version !== false && $version->ID != 0) { $fields->dataFieldByName('SnippetText')->setValue($version->Text); $fields->dataFieldByName('LastModified')->setValue($version->LastEdited); $fields->dataFieldByName('CurrentVersionID')->setValue($version->ID); } $form->Fields()->insertBefore(new LiteralField('NotCurrentVersion', '<p class="message warning">' . _t('CodeBank.NOT_CURRENT_VERSION', '_You are viewing a past version of this snippet\'s content, {linkopen}click here{linkclose} to view the current version', array('linkopen' => '<a href="admin/codeBank/show/' . $record->ID . '">', 'linkclose' => '</a>')) . '</p>'), 'Title'); } $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); $this->extend('updateEditForm', $form); $form->Actions()->push(new LiteralField('CodeBankVersion', '<p class="codeBankVersion">Code Bank: ' . $this->getVersion() . '</p>')); Requirements::add_i18n_javascript(CB_DIR . '/javascript/lang'); Requirements::add_i18n_javascript('mysite/javascript/lang'); Requirements::javascript(CB_DIR . '/javascript/external/jquery-zclip/jquery.zclip.min.js'); Requirements::javascript(CB_DIR . '/javascript/CodeBank.ViewForm.js'); //Display message telling user to run dev/build because the version numbers are out of sync if (CB_VERSION != '@@VERSION@@' && CodeBankConfig::CurrentConfig()->Version != CB_VERSION . ' ' . CB_BUILD_DATE) { $form->Fields()->insertBefore(new LiteralField('DBUpgrade', '<p class="message error">' . _t('CodeBank.UPDATE_NEEDED', '_A database upgrade is required please run {startlink}dev/build{endlink}.', array('startlink' => '<a href="dev/build?flush=all">', 'endlink' => '</a>')) . '</p>'), 'Title'); } else { if ($this->hasOldTables()) { $form->Fields()->insertBefore(new LiteralField('DBUpgrade', '<p class="message warning">' . _t('CodeBank.MIGRATION_AVAILABLE', '_It appears you are upgrading from Code Bank 2.2.x, your old data can be migrated {startlink}click here to begin{endlink}, though it is recommended you backup your database first.', array('startlink' => '<a href="dev/tasks/CodeBankLegacyMigrate">', 'endlink' => '</a>')) . '</p>'), 'Title'); } } return $form; } else { if ($id) { $form = CMSForm::create($this, 'EditForm', new FieldList(new TabSet('Root', new Tab('Main', ' ', new LabelField('DoesntExistLabel', _t('CodeBank.SNIPPIT_NOT_EXIST', '_Snippit does not exist'))))), new FieldList())->setHTMLID('Form_EditForm'); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->addExtraClass('center ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); //Display message telling user to run dev/build because the version numbers are out of sync if (CB_VERSION != '@@VERSION@@' && CodeBankConfig::CurrentConfig()->Version != CB_VERSION . ' ' . CB_BUILD_DATE) { $form->Fields()->insertBefore(new LiteralField('DBUpgrade', '<p class="message error">' . _t('CodeBank.UPDATE_NEEDED', '_A database upgrade is required please run {startlink}dev/build{endlink}.', array('startlink' => '<a href="dev/build?flush=all">', 'endlink' => '</a>')) . '</p>'), 'DoesntExist'); } else { if ($this->hasOldTables()) { $form->Fields()->insertBefore(new LiteralField('DBUpgrade', '<p class="message warning">' . _t('CodeBank.MIGRATION_AVAILABLE', '_It appears you are upgrading from Code Bank 2.2.x, your old data can be migrated {startlink}click here to begin{endlink}, though it is recommended you backup your database first.', array('startlink' => '<a href="dev/tasks/CodeBankLegacyMigrate">', 'endlink' => '</a>')) . '</p>'), 'DoesntExistLabel'); } } } else { $form = $this->EmptyForm(); if (Session::get('CodeBank.deletedSnippetID')) { $form->Fields()->push(new HiddenField('ID', 'ID', Session::get('CodeBank.deletedSnippetID'))); } //Display message telling user to run dev/build because the version numbers are out of sync if (CB_VERSION != '@@VERSION@@' && CodeBankConfig::CurrentConfig()->Version != CB_VERSION . ' ' . CB_BUILD_DATE) { $form->Fields()->push(new LiteralField('DBUpgrade', '<p class="message error">' . _t('CodeBank.UPDATE_NEEDED', '_A database upgrade is required please run {startlink}dev/build{endlink}.', array('startlink' => '<a href="dev/build?flush=all">', 'endlink' => '</a>')) . '</p>')); } else { if ($this->hasOldTables()) { $form->Fields()->push(new LiteralField('DBUpgrade', '<p class="message warning">' . _t('CodeBank.MIGRATION_AVAILABLE', '_It appears you are upgrading from Code Bank 2.2.x, your old data can be migrated {startlink}click here to begin{endlink}, though it is recommended you backup your database first.', array('startlink' => '<a href="dev/tasks/CodeBankLegacyMigrate">', 'endlink' => '</a>')) . '</p>')); } } } } $form->disableDefaultAction(); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->addExtraClass('center ' . $this->BaseCSSClasses()); $form->Actions()->push(new LiteralField('CodeBankVersion', '<p class="codeBankVersion">Code Bank: ' . $this->getVersion() . '</p>')); return $form; }