public function Form() { $fields = new FieldList(); $source = array(); $fields->push(new HeaderField('Header', _t('RemoveOrphanedPagesTask.HEADER', 'Remove all orphaned pages task'))); $fields->push(new LiteralField('Description', $this->description)); $orphans = $this->getOrphanedPages($this->orphanedSearchClass); if ($orphans) { foreach ($orphans as $orphan) { $latestVersion = Versioned::get_latest_version($this->orphanedSearchClass, $orphan->ID); $latestAuthor = DataObject::get_by_id('Member', $latestVersion->AuthorID); $stageRecord = Versioned::get_one_by_stage($this->orphanedSearchClass, 'Stage', sprintf("\"%s\".\"ID\" = %d", ClassInfo::baseDataClass($this->orphanedSearchClass), $orphan->ID)); $liveRecord = Versioned::get_one_by_stage($this->orphanedSearchClass, 'Live', sprintf("\"%s\".\"ID\" = %d", ClassInfo::baseDataClass($this->orphanedSearchClass), $orphan->ID)); $label = sprintf('<a href="admin/pages/edit/show/%d">%s</a> <small>(#%d, Last Modified Date: %s, Last Modifier: %s, %s)</small>', $orphan->ID, $orphan->Title, $orphan->ID, Date::create($orphan->LastEdited)->Nice(), $latestAuthor ? $latestAuthor->Title : 'unknown', $liveRecord ? 'is published' : 'not published'); $source[$orphan->ID] = $label; } } if ($orphans && $orphans->Count()) { $fields->push(new CheckboxSetField('OrphanIDs', false, $source)); $fields->push(new LiteralField('SelectAllLiteral', sprintf('<p><a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'checked\'); return false;">%s</a> ', _t('RemoveOrphanedPagesTask.SELECTALL', 'select all')))); $fields->push(new LiteralField('UnselectAllLiteral', sprintf('<a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'\'); return false;">%s</a></p>', _t('RemoveOrphanedPagesTask.UNSELECTALL', 'unselect all')))); $fields->push(new OptionSetField('OrphanOperation', _t('RemoveOrphanedPagesTask.CHOOSEOPERATION', 'Choose operation:'), array('rebase' => _t('RemoveOrphanedPagesTask.OPERATION_REBASE', sprintf('Rebase selected to a new holder page "%s" and unpublish. None of these pages will show up for website visitors.', $this->rebaseHolderTitle())), 'remove' => _t('RemoveOrphanedPagesTask.OPERATION_REMOVE', 'Remove selected from all stages (WARNING: Will destroy all selected pages from both stage and live)')), 'rebase')); $fields->push(new LiteralField('Warning', sprintf('<p class="message">%s</p>', _t('RemoveOrphanedPagesTask.DELETEWARNING', 'Warning: These operations are not reversible. Please handle with care.')))); } else { $fields->push(new LiteralField('NotFoundLabel', sprintf('<p class="message">%s</p>', _t('RemoveOrphanedPagesTask.NONEFOUND', 'No orphans found')))); } $form = new Form($this, 'Form', $fields, new FieldList(new FormAction('doSubmit', _t('RemoveOrphanedPagesTask.BUTTONRUN', 'Run')))); if (!$orphans || !$orphans->Count()) { $form->makeReadonly(); } return $form; }
/** * Need to update the edit form AFTER it's been transformed to read only so that the workflow stuff is still * allowed to be added with 'write' permissions * * @param Form $form */ public function updateEditForm(Form $form) { $svc = singleton('WorkflowService'); $p = $form->getRecord(); $active = $svc->getWorkflowFor($p); if ($active) { $fields = $form->Fields(); $current = $active->CurrentAction(); $wfFields = $active->getWorkflowFields(); $allowed = array_keys($wfFields->saveableFields()); $data = array(); foreach ($allowed as $fieldName) { $data[$fieldName] = $current->{$fieldName}; } $fields->addFieldsToTab('Root.WorkflowActions', $wfFields); $form->loadDataFrom($data); if (!$p->canEditWorkflow()) { $form->makeReadonly(); } } }
/** * Need to update the edit form AFTER it's been transformed to read only so that the workflow stuff is still * allowed to be added with 'write' permissions * * @param Form $form */ public function updateEditForm(Form $form) { Requirements::javascript(ADVANCED_WORKFLOW_DIR . '/javascript/advanced-workflow-cms.js'); $svc = singleton('WorkflowService'); $p = $form->getRecord(); $active = $svc->getWorkflowFor($p); if ($active) { $fields = $form->Fields(); $current = $active->CurrentAction(); $wfFields = $active->getWorkflowFields(); $allowed = array_keys($wfFields->saveableFields()); $data = array(); foreach ($allowed as $fieldName) { $data[$fieldName] = $current->{$fieldName}; } $fields->findOrMakeTab('Root.WorkflowActions', _t('Workflow.WorkflowActionsTabTitle', 'Workflow Actions')); $fields->addFieldsToTab('Root.WorkflowActions', $wfFields); $form->loadDataFrom($data); if (!$p->canEditWorkflow()) { $form->makeReadonly(); } } }
/** * Returns a form for viewing the attached model * * @return Form */ public function ViewForm() { $fields = $this->currentRecord->getCMSFields(); $form = new Form($this, "EditForm", $fields, new FieldSet()); $form->loadDataFrom($this->currentRecord); $form->makeReadonly(); return $form; }
/** * Return the form that displays the details of a folder, including a file list and fields for editing the folder name. */ function getEditForm($id) { if ($id && $id != "root") { $record = DataObject::get_by_id("File", $id); } else { $record = singleton("Folder"); } if ($record) { $fields = $record->getCMSFields(); $actions = new FieldSet(); // Only show save button if not 'assets' folder if ($record->canEdit() && $id != 'root') { $actions = new FieldSet(new FormAction('save', _t('AssetAdmin.SAVEFOLDERNAME', 'Save folder name'))); } $form = new Form($this, "EditForm", $fields, $actions); if ($record->ID) { $form->loadDataFrom($record); } else { $form->loadDataFrom(array("ID" => "root", "URL" => Director::absoluteBaseURL() . 'assets/')); } if (!$record->canEdit()) { $form->makeReadonly(); } $this->extend('updateEditForm', $form); return $form; } }
/** * Builds an item edit form. The arguments to getCMSFields() are the popupController and * popupFormName, however this is an experimental API and may change. * * @todo In the future, we will probably need to come up with a tigher object representing a partially * complete controller with gaps for extra functionality. This, for example, would be a better way * of letting Security/login put its log-in form inside a UI specified elsewhere. * * @return Form */ public function ItemEditForm() { $list = $this->gridField->getList(); if (empty($this->record)) { $controller = $this->getToplevelController(); $noActionURL = $controller->removeAction($_REQUEST['url']); $controller->getResponse()->removeHeader('Location'); //clear the existing redirect return $controller->redirect($noActionURL, 302); } $canView = $this->record->canView(); $canEdit = $this->record->canEdit(); $canDelete = $this->record->canDelete(); $canCreate = $this->record->canCreate(); if (!$canView) { $controller = $this->getToplevelController(); // TODO More friendly error return $controller->httpError(403); } $actions = new FieldList(); if ($this->record->ID !== 0) { if ($canEdit) { $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Save', 'Save'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')); } if ($canDelete) { $actions->push(FormAction::create('doDelete', _t('GridFieldDetailForm.Delete', 'Delete'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-destructive action-delete')); } } else { // adding new record //Change the Save label to 'Create' $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Create', 'Create'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'add')); // Add a Cancel link which is a button-like link and link back to one level up. $curmbs = $this->Breadcrumbs(); if ($curmbs && $curmbs->count() >= 2) { $one_level_up = $curmbs->offsetGet($curmbs->count() - 2); $text = sprintf("<a class=\"%s\" href=\"%s\">%s</a>", "crumb ss-ui-button ss-ui-action-destructive cms-panel-link ui-corner-all", $one_level_up->Link, _t('GridFieldDetailForm.CancelBtn', 'Cancel')); $actions->push(new LiteralField('cancelbutton', $text)); } } $fields = $this->component->getFields(); if (!$fields) { $fields = $this->record->getCMSFields(); } // If we are creating a new record in a has-many list, then // pre-populate the record's foreign key. Also disable the form field as // it has no effect. if ($list instanceof HasManyList) { $key = $list->getForeignKey(); $id = $list->getForeignID(); if (!$this->record->isInDB()) { $this->record->{$key} = $id; } if ($field = $fields->dataFieldByName($key)) { $fields->makeFieldReadonly($field); } } // Caution: API violation. Form expects a Controller, but we are giving it a RequestHandler instead. // Thanks to this however, we are able to nest GridFields, and also access the initial Controller by // dereferencing GridFieldDetailForm_ItemRequest->getController() multiple times. See getToplevelController // below. $form = new Form($this, 'ItemEditForm', $fields, $actions, $this->component->getValidator()); $form->loadDataFrom($this->record, $this->record->ID == 0 ? Form::MERGE_IGNORE_FALSEISH : Form::MERGE_DEFAULT); if ($this->record->ID && !$canEdit) { // Restrict editing of existing records $form->makeReadonly(); // Hack to re-enable delete button if user can delete if ($canDelete) { $form->Actions()->fieldByName('action_doDelete')->setReadonly(false); } } elseif (!$this->record->ID && !$canCreate) { // Restrict creation of new records $form->makeReadonly(); } // Load many_many extraData for record. // Fields with the correct 'ManyMany' namespace need to be added manually through getCMSFields(). if ($list instanceof ManyManyList) { $extraData = $list->getExtraData('', $this->record->ID); $form->loadDataFrom(array('ManyMany' => $extraData)); } // TODO Coupling with CMS $toplevelController = $this->getToplevelController(); if ($toplevelController && $toplevelController instanceof LeftAndMain) { // Always show with base template (full width, no other panels), // regardless of overloaded CMS controller templates. // TODO Allow customization, e.g. to display an edit form alongside a search form from the CMS controller $form->setTemplate('LeftAndMain_EditForm'); $form->addExtraClass('cms-content cms-edit-form center'); $form->setAttribute('data-pjax-fragment', 'CurrentForm Content'); if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); $form->addExtraClass('cms-tabset'); } $form->Backlink = $this->getBackLink(); } $cb = $this->component->getItemEditFormCallback(); if ($cb) { $cb($form, $this); } $this->extend("updateItemEditForm", $form); return $form; }
/** * Return the form for editing */ function getEditForm($id = null, $fields = null) { $record = null; if (!$id) { $id = $this->getCurrentPageID(); } if ($id && $id != "root") { $record = $this->getRecord($id); } if ($record) { $fields = $record->getCMSFields(); // If we're editing an external source or item, and it can be imported // then add the "Import" tab. $isSource = $record instanceof ExternalContentSource; $isItem = $record instanceof ExternalContentItem; if (($isSource || $isItem) && $record->canImport()) { $allowedTypes = $record->allowedImportTargets(); if (isset($allowedTypes['sitetree'])) { $fields->addFieldToTab('Root.Import', new TreeDropdownField("MigrationTarget", _t('ExternalContent.MIGRATE_TARGET', 'Page to import into'), 'SiteTree')); } if (isset($allowedTypes['file'])) { $fields->addFieldToTab('Root.Import', new TreeDropdownField("FileMigrationTarget", _t('ExternalContent.FILE_MIGRATE_TARGET', 'Folder to import into'), 'Folder')); } $fields->addFieldToTab('Root.Import', new CheckboxField("IncludeSelected", _t('ExternalContent.INCLUDE_SELECTED', 'Include Selected Item in Import'))); $fields->addFieldToTab('Root.Import', new CheckboxField("IncludeChildren", _t('ExternalContent.INCLUDE_CHILDREN', 'Include Child Items in Import'), true)); $duplicateOptions = array(ExternalContentTransformer::DS_OVERWRITE => ExternalContentTransformer::DS_OVERWRITE, ExternalContentTransformer::DS_DUPLICATE => ExternalContentTransformer::DS_DUPLICATE, ExternalContentTransformer::DS_SKIP => ExternalContentTransformer::DS_SKIP); $fields->addFieldToTab('Root.Import', new OptionsetField("DuplicateMethod", _t('ExternalContent.DUPLICATES', 'Select how duplicate items should be handled'), $duplicateOptions, $duplicateOptions[ExternalContentTransformer::DS_SKIP])); if (class_exists('QueuedJobDescriptor')) { $repeats = array(0 => 'None', 300 => '5 minutes', 900 => '15 minutes', 1800 => '30 minutes', 3600 => '1 hour', 33200 => '12 hours', 86400 => '1 day', 604800 => '1 week'); $fields->addFieldToTab('Root.Import', new DropdownField('Repeat', 'Repeat import each ', $repeats)); } $migrateButton = FormAction::create('migrate', _t('ExternalContent.IMPORT', 'Start Importing'))->setAttribute('data-icon', 'arrow-circle-double')->setUseButtonTag(true); $fields->addFieldToTab('Root.Import', new LiteralField('MigrateActions', "<div class='Actions'>{$migrateButton->forTemplate()}</div>")); } $fields->push($hf = new HiddenField("ID")); $hf->setValue($id); $fields->push($hf = new HiddenField("Version")); $hf->setValue(1); $actions = new FieldList(); $actions = CompositeField::create()->setTag('fieldset')->addExtraClass('ss-ui-buttonset'); $actions = new FieldList($actions); // Only show save button if not 'assets' folder if ($record->canEdit()) { $actions->push(FormAction::create('save', _t('ExternalContent.SAVE', 'Save'))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true)); } if ($isSource && $record->canDelete()) { $actions->push(FormAction::create('delete', _t('ExternalContent.DELETE', 'Delete'))->addExtraClass('delete ss-ui-action-destructive')->setAttribute('data-icon', 'decline')->setUseButtonTag(true)); } $form = new Form($this, "EditForm", $fields, $actions); if ($record->ID) { $form->loadDataFrom($record); } else { $form->loadDataFrom(array("ID" => "root", "URL" => Director::absoluteBaseURL() . self::$url_segment)); } if (!$record->canEdit()) { $form->makeReadonly(); } } else { // Create a dummy form $fields = new FieldList(); $form = new Form($this, "EditForm", $fields, new FieldList()); } $form->addExtraClass('cms-edit-form center ss-tabset ' . $this->BaseCSSClasses()); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); $this->extend('updateEditForm', $form); return $form; }
function compareversions() { $id = $this->urlParams['ID']; $version1 = $_REQUEST['From']; $version2 = $_REQUEST['To']; if ($version1 > $version2) { $toVersion = $version1; $fromVersion = $version2; } else { $toVersion = $version2; $fromVersion = $version1; } $page = DataObject::get_by_id("SiteTree", $id); $record = $page->compareVersions($fromVersion, $toVersion); if ($record) { $fields = $record->getCMSFields($this); $fields->push(new HiddenField("ID")); $fields->push(new HiddenField("Version")); $fields->insertBefore(new HeaderField(sprintf(_t('CMSMain.COMPARINGV', "You are comparing versions #%d and #%d"), $fromVersion, $toVersion)), "Root"); $actions = new FieldSet(); $form = new Form($this, "EditForm", $fields, $actions); $form->loadDataFrom($record); $form->loadDataFrom(array("ID" => $id, "Version" => $fromVersion)); $form->makeReadonly(); foreach ($form->Fields()->dataFields() as $field) { $field->dontEscape = true; } return $this->sendFormToBrowser(array("EditForm" => $form)); } }
function getEditForm($id) { if ($id && $id != "root") { $record = DataObject::get_by_id("DynamicTemplate", $id); } else { return new Form($this, "EditForm", new FieldSet(new LabelField("selectSomething", "Please a select a dynamic template on the left, or Create or Upload a new one.")), new FieldSet()); } if ($record) { $fields = $record->getCMSFields(); $actions = new FieldSet(); // Only show save button if not 'assets' folder if ($record->canEdit()) { $actions = new FieldSet(new FormAction('save', _t('AssetAdmin.SAVEDYNAMICTEMPLATE', 'Save dynamic template'))); } $form = new Form($this, "EditForm", $fields, $actions); if ($record->ID) { $form->loadDataFrom($record); } else { $form->loadDataFrom(array("ID" => "root", "URL" => Director::absoluteBaseURL() . self::$url_segment . '/')); } if (!$record->canEdit()) { $form->makeReadonly(); } $this->extend('updateEditForm', $form); return $form; } }
/** * Builds an item edit form. The arguments to getCMSFields() are the popupController and * popupFormName, however this is an experimental API and may change. * * @todo In the future, we will probably need to come up with a tigher object representing a partially * complete controller with gaps for extra functionality. This, for example, would be a better way * of letting Security/login put its log-in form inside a UI specified elsewhere. * * @return Form */ public function ItemEditForm() { $list = $this->gridField->getList(); if (empty($this->record)) { $controller = $this->getToplevelController(); $url = $controller->getRequest()->getURL(); $noActionURL = $controller->removeAction($url); $controller->getResponse()->removeHeader('Location'); //clear the existing redirect return $controller->redirect($noActionURL, 302); } $canView = $this->record->canView(); $canEdit = $this->record->canEdit(); $canDelete = $this->record->canDelete(); $canCreate = $this->record->canCreate(); if (!$canView) { $controller = $this->getToplevelController(); // TODO More friendly error return $controller->httpError(403); } // Build actions $actions = $this->getFormActions(); // If we are creating a new record in a has-many list, then // pre-populate the record's foreign key. if ($list instanceof HasManyList && !$this->record->isInDB()) { $key = $list->getForeignKey(); $id = $list->getForeignID(); $this->record->{$key} = $id; } $fields = $this->component->getFields(); if (!$fields) { $fields = $this->record->getCMSFields(); } // If we are creating a new record in a has-many list, then // Disable the form field as it has no effect. if ($list instanceof HasManyList) { $key = $list->getForeignKey(); if ($field = $fields->dataFieldByName($key)) { $fields->makeFieldReadonly($field); } } // Caution: API violation. Form expects a Controller, but we are giving it a RequestHandler instead. // Thanks to this however, we are able to nest GridFields, and also access the initial Controller by // dereferencing GridFieldDetailForm_ItemRequest->getController() multiple times. See getToplevelController // below. $form = new Form($this, 'ItemEditForm', $fields, $actions, $this->component->getValidator()); $form->loadDataFrom($this->record, $this->record->ID == 0 ? Form::MERGE_IGNORE_FALSEISH : Form::MERGE_DEFAULT); if ($this->record->ID && !$canEdit) { // Restrict editing of existing records $form->makeReadonly(); // Hack to re-enable delete button if user can delete if ($canDelete) { $form->Actions()->fieldByName('action_doDelete')->setReadonly(false); } } elseif (!$this->record->ID && !$canCreate) { // Restrict creation of new records $form->makeReadonly(); } // Load many_many extraData for record. // Fields with the correct 'ManyMany' namespace need to be added manually through getCMSFields(). if ($list instanceof ManyManyList) { $extraData = $list->getExtraData('', $this->record->ID); $form->loadDataFrom(array('ManyMany' => $extraData)); } // TODO Coupling with CMS $toplevelController = $this->getToplevelController(); if ($toplevelController && $toplevelController instanceof LeftAndMain) { // Always show with base template (full width, no other panels), // regardless of overloaded CMS controller templates. // TODO Allow customization, e.g. to display an edit form alongside a search form from the CMS controller $form->setTemplate('LeftAndMain_EditForm'); $form->addExtraClass('cms-content cms-edit-form center'); $form->setAttribute('data-pjax-fragment', 'CurrentForm Content'); if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); $form->addExtraClass('cms-tabset'); } $form->Backlink = $this->getBackLink(); } $cb = $this->component->getItemEditFormCallback(); if ($cb) { $cb($form, $this); } $this->extend("updateItemEditForm", $form); return $form; }
/** * Return the form that displays the details of a folder, including a file list and fields for editing the folder name. */ function getEditForm($id) { if ($id && $id != "root") { $record = DataObject::get_by_id("File", $id); } else { $record = singleton("Folder"); } if ($record) { $fields = $record->getCMSFields(); $actions = new FieldSet(); // Only show save button if not 'assets' folder if ($record->userCanEdit() && $id != "root") { $actions = new FieldSet(new FormAction('save', _t('AssetAdmin.SAVEFOLDERNAME', 'Save folder name'))); } $form = new Form($this, "EditForm", $fields, $actions); if ($record->ID) { $form->loadDataFrom($record); } else { $form->loadDataFrom(array("ID" => "root", "URL" => Director::absoluteBaseURL() . 'assets/')); } // @todo: These workflow features aren't really appropriate for all projects if (Member::currentUser()->_isAdmin() && project() == 'mot') { $fields->addFieldsToTab('Root.Workflow', new DropdownField("Owner", _t('AssetAdmin.OWNER', 'Owner'), Member::map())); $fields->addFieldsToTab('Root.Workflow', new TreeMultiselectField("CanUse", _t('AssetAdmin.CONTENTUSABLEBY', 'Content usable by'))); $fields->addFieldsToTab('Root.Workflow', new TreeMultiselectField("CanEdit", _t('AssetAdmin.CONTENTMODBY', 'Content modifiable by'))); } if (!$record->userCanEdit()) { $form->makeReadonly(); } return $form; } }
public function getNewsletterEditForm($myId) { $email = DataObject::get_by_id("Newsletter", $myId); if ($email) { $fields = $email->getCMSFields($this); $fields->push($idField = new HiddenField("ID")); $idField->setValue($myId); $fields->push($ParentidField = new HiddenField("ParentID")); $ParentidField->setValue($email->ParentID); $fields->push($typeField = new HiddenField("Type")); $typeField->setValue('Newsletter'); //$fields->push(new HiddenField("executeForm", "", "EditForm") ); $actions = new FieldSet(); if ($email->SentDate) { $actions->push(new FormAction('send', _t('NewsletterAdmin.RESEND', 'Resend'))); } else { $actions->push(new FormAction('send', _t('NewsletterAdmin.SEND', 'Send...'))); } $actions->push(new FormAction('save', _t('NewsletterAdmin.SAVE', 'Save'))); $form = new Form($this, "EditForm", $fields, $actions); $form->loadDataFrom($email); if ($email->Status != 'Draft') { $form->makeReadonly(); } // user_error( $form->FormAction(), E_USER_ERROR ); return $form; } else { user_error('Unknown Email ID: ' . $myId, E_USER_ERROR); } }