/**
  * Updates the CMS fields adding the fields defined in this extension
  * @param {FieldList} $fields Field List that new fields will be added to
  */
 public function updateSettingsFields(FieldList $fields)
 {
     $kapostRefID = $this->owner->KapostRefID;
     if (!empty($kapostRefID)) {
         if (CMSPageSettingsController::has_extension('KapostPageSettingsControllerExtension')) {
             $messageContent = _t('KapostSiteTreeExtension.KAPOST_CONTENT_WARNING_RO', '_This Page\'s content is being populated by Kapost, some fields are not editable.');
         } else {
             $messageContent = _t('KapostSiteTreeExtension.KAPOST_CONTENT_WARNING', '_This Page\'s content is being populated by Kapost.');
         }
         //Edit in kapost link
         $kapostBase = KapostAdmin::config()->kapost_base_url;
         if (!empty($kapostBase)) {
             $messageContent .= ' <a href="' . Controller::join_links($kapostBase, 'posts', $kapostRefID) . '" target="_blank">' . _t('KapostSiteTreeExtension.KAPOST_CONTENT_EDIT_LABEL', '_Click here to edit in Kapost') . '</a>';
         }
         $fields->insertBefore(new LiteralField('KapostContentWarning', '<div class="message warning">' . $messageContent . '</div>'), 'ClassName');
         //Detect Incoming Changes
         if (Permission::check('CMS_ACCESS_KapostAdmin')) {
             $incoming = KapostObject::get()->filter('KapostRefID', Convert::raw2sql($kapostRefID));
             if ($incoming->count() >= 1) {
                 $link = Controller::join_links(AdminRootController::config()->url_base, KapostAdmin::config()->url_segment, 'KapostObject/EditForm/field/KapostObject/item', $incoming->first()->ID, 'edit');
                 $messageContent = _t('KapostSiteTreeExtension.KAPOST_INCOMING', '_There are incoming changes from Kapost waiting for this page.') . ' ' . '<a href="' . $link . '" class="cms-panel-link">' . _t('KapostSiteTreeExtension.KAPOST_INCOMING_VIEW', '_Click here to view the changes') . '</a>';
                 $fields->insertBefore(new LiteralField('KapostIncomingWarning', '<div class="message warning">' . $messageContent . '</div>'), 'ClassName');
             }
         }
     }
 }
 /**
  * Gets fields used in the cms
  * @return {FieldList} Fields to be used
  */
 public function getCMSFields()
 {
     $kapostBase = KapostAdmin::config()->kapost_base_url;
     if ($kapostBase[strlen($kapostBase) - 1] != '/') {
         $kapostBase .= '/';
     }
     $fields = new FieldList(new ReadonlyField('Title', $this->fieldLabel('Title')), new ReadonlyField('Created', _t('KapostConversionHistory.CONVERSION_DATE', '_Conversion Date')), new ReadonlyField('ConverterName', $this->fieldLabel('ConverterName')), new ReadonlyField('KapostChangeTypeNice', $this->fieldLabel('KapostChangeType')), new ReadonlyField('KapostAuthor', $this->fieldLabel('KapostAuthor')), new ReadonlyField('DestinationTypeNice', $this->fieldLabel('DestinationType')), $kapostRef = ReadonlyField::create('KapostRefID_linked', $this->fieldLabel('KapostRefID'), !empty($kapostBase) ? '<a href="' . htmlentities($kapostBase . 'posts/' . $this->KapostRefID) . '" target="_blank">' . htmlentities($this->KapostRefID) . '</a>' : $this->KapostRefID), $destination = ReadonlyField::create('Destination', $this->fieldLabel('DestinationID'), '<a href="' . htmlentities($this->getDestinationLink()) . '" class="kapost-panel-link">' . _t('KapostConversionHistory.CONVERTED_TO_OBJECT', '_View Destination Object') . '</a>'));
     $kapostRef->dontEscape = true;
     $destination->dontEscape = true;
     //Allow extensions to add/remove fields
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
 /**
  * Handles conversion of the current record
  * @param {array} $data Submitted Data
  * @param {Form} $form Submitting Form
  * @return {mixed} Returns an SS_HTTPResponse or an HTML string
  */
 public function doConvertObject($data, Form $form)
 {
     //Make sure the record still exists
     if (empty($this->record) || $this->record === false || !$this->record->exists()) {
         return $this->httpError(404);
     }
     if ($data['ConvertMode'] == 'ReplacePage') {
         if (empty($data['ReplacePageID']) || $data['ReplacePageID'] == 0) {
             $form->sessionMessage(_t('KapostAdmin.NO_REPLACE_PAGE_TARGET', '_You must select a page to replace'), 'error');
             return $this->popupController->redirectBack();
         }
         try {
             $redirectURL = $this->replacePage($data, $form);
         } catch (ValidationException $e) {
             //Catch any validation exception and return it as an error message on the form
             $form->sessionMessage($e->getMessage(), 'error');
             return $this->popupController->redirectBack();
         }
         if ($redirectURL === false) {
             $form->sessionMessage(_t('KapostAdmin.ERROR_COULD_NOT_REPLACE', '_Sorry an error occured and the target page could not be replaced.'), 'error');
             return $this->popupController->redirectBack();
         } else {
             Requirements::clear();
             Requirements::customScript('window.parent.jQuery(\'.cms-edit-form.KapostAdmin\').entwine(\'ss\').panelRedirect(' . json_encode($redirectURL) . ')');
             //Clean up the expired previews
             $this->cleanUpExpiredPreviews();
             return $this->customise(array('Title' => null, 'Content' => null, 'Form' => null))->renderWith('CMSDialog');
         }
     } else {
         if ($data['ConvertMode'] == 'NewPage') {
             try {
                 $redirectURL = $this->newPage($data, $form);
             } catch (ValidationException $e) {
                 //Catch any validation exception and return it as an error message on the form
                 $form->sessionMessage($e->getMessage(), 'error');
                 return $this->popupController->redirectBack();
             }
             if ($redirectURL === false) {
                 $form->sessionMessage(_t('KapostAdmin.ERROR_COULD_NOT_CREATE', '_Sorry an error occured and the page could not be created.'), 'error');
                 return $this->popupController->redirectBack();
             } else {
                 Requirements::clear();
                 Requirements::customScript('window.parent.jQuery(\'.cms-edit-form.KapostAdmin\').entwine(\'ss\').panelRedirect(' . json_encode($redirectURL) . ')');
                 //Clean up the expired previews
                 $this->cleanUpExpiredPreviews();
                 return $this->customise(array('Title' => null, 'Content' => null, 'Form' => null))->renderWith('CMSDialog');
             }
         }
     }
     //Allow extensions to convert the object
     if (in_array($data['ConvertMode'], KapostAdmin::config()->extra_conversion_modes)) {
         try {
             $results = $this->extend('doConvert' . $data['ConvertMode'], $this->record, $data, $form);
         } catch (ValidationException $e) {
             //Catch any validation exception and return it as an error message on the form
             $form->sessionMessage($e->getMessage(), 'error');
             return $this->popupController->redirectBack();
         }
         if (count($results) > 0) {
             foreach ($results as $result) {
                 if ($result !== false) {
                     Requirements::clear();
                     Requirements::customScript('window.parent.jQuery(\'.cms-edit-form.KapostAdmin\').entwine(\'ss\').panelRedirect(' . json_encode($result) . ')');
                     //Clean up the expired previews
                     $this->cleanUpExpiredPreviews();
                     return $this->customise(array('Title' => null, 'Content' => null, 'Form' => null))->renderWith('CMSDialog');
                 }
             }
             $message = $form->Message();
             if (empty($message)) {
                 $form->sessionMessage(_t('KapostAdmin.GENERIC_CONVERSION_ERROR', '_Conversion method returns an error and no specific message'), 'error');
             }
             //All failed redirect back
             return $this->popupController->redirectBack();
         }
     }
     $form->sessionMessage(_t('KapostAdmin.UNKNOWN_CONVERSION_MODE', '_Unknown conversion mode: {mode}', array('mode' => $data['ConvertMode'])), 'error');
     return $this->popupController->redirectBack();
 }
コード例 #4
0
 /**
  * Gets the edit link for the Kapost Object
  * @return {string} Edit link for the Kapost Object
  */
 public function CMSEditLink()
 {
     return Controller::join_links(LeftAndMain::config()->url_base, KapostAdmin::config()->url_segment, 'KapostObject/EditForm/field/KapostObject/item', $this->ID, 'edit');
 }