public function updateLinkForm($form) { Requirements::javascript("linkableobjects/javascript/CustomHtmlEditorField.js"); $count = 0; foreach ($form->Fields() as $field) { $count++; if ($count == 2) { $linkType = $field->fieldByName('LinkType'); $types = $linkType->getSource(); $link = new HtmlEditorField_LinkObjects(); $linkableObjects = $link->getLinkableObjects(); foreach ($linkableObjects as $object => $title) { $types[$object] = $title; $picker = new DataObjectPicker($object . 'LinkID', $title); $picker->setConfig('limit', 5); $picker->setConfig('classToPick', $object); $picker->setForm($form); $field->insertBefore($picker, 'Description'); } $linkMap = new HiddenField('LinkableObjects'); $linkMap->setAttribute('data-map', json_encode($linkableObjects)); $field->push($linkMap); $linkType->setSource($types); } } }
/** * Builds an item edit form * * @return Form */ public function ItemEditForm() { // If there are no record set, redirect back to the "main" model admin if (empty($this->record) || $this->record->ID == 0) { $controller = Controller::curr(); $noActionURL = $controller->removeAction($_REQUEST['url']); $controller->getResponse()->removeHeader('Location'); //clear the existing redirect return $controller->redirect($noActionURL, 302); } // Create form field $fields = new FieldList(); $chartData = new HiddenField('FlowchartData'); $chartData->setAttribute('data-chart-storage', 'true'); $fields->push($chartData); $existsOnLive = $this->record->getExistsOnLive(); // Create the action buttons $majorActions = CompositeField::create()->setName('MajorActions')->setTag('fieldset')->addExtraClass('ss-ui-buttonset'); $actions = new FieldList(array($majorActions)); if ($this->record->canEdit()) { $majorActions->push(FormAction::create('doSave', _t('SiteTree.BUTTONSAVED', 'Saved'))->setAttribute('data-icon', 'accept')->setAttribute('data-icon-alternate', 'addpage')->setAttribute('data-text-alternate', _t('CMSMain.SAVEDRAFT', 'Save draft'))->setUseButtonTag(true)); } if ($this->record->canPublish() && !$this->record->IsDeletedFromStage) { // "publish", as with "save", it supports an alternate state to show when action is needed. $majorActions->push($publish = FormAction::create('publish', _t('SiteTree.BUTTONPUBLISHED', 'Published'))->setAttribute('data-icon', 'accept')->setAttribute('data-icon-alternate', 'disk')->setAttribute('data-text-alternate', _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & publish'))->setUseButtonTag(true)); // Set up the initial state of the button to reflect the state of the underlying SiteTree object. if ($this->record->stagesDiffer('Stage', 'Live')) { $publish->addExtraClass('ss-ui-alternate'); } } $form = new Form($this, 'ItemEditForm', $fields, $actions); $form->loadDataFrom($this->record); $form->Backlink = $this->getBackLink(); $form->setTemplate('Flowchart_EditForm'); return $form; }