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;
 }
Example #2
0
 /**
  * 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;
 }
 /**
  * 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;
 }