From 878cf541b9020377bb455bfcffa88f8c0276e184 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 16 Apr 2013 11:47:56 +0200 Subject: [PATCH] Better UI feedback on VirtualPage states (fixes #1594) --- code/model/VirtualPage.php | 68 +++++++++++++++++++++++++++++++------- lang/en.yml | 4 +-- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/code/model/VirtualPage.php b/code/model/VirtualPage.php index c8e229cb..ef81c1a3 100644 --- a/code/model/VirtualPage.php +++ b/code/model/VirtualPage.php @@ -170,7 +170,7 @@ class VirtualPage extends Page { // Setup the linking to the original page. $copyContentFromField = new TreeDropdownField( "CopyContentFromID", - _t('VirtualPage.CHOOSE', "Choose a page to link to"), + _t('VirtualPage.CHOOSE', "Linked Page"), "SiteTree" ); // filter doesn't let you select children of virtual pages as as source page @@ -184,27 +184,71 @@ class VirtualPage extends Page { $fields->replaceField($virtualField, $fields->dataFieldByName($virtualField)->transform($roTransformation)); } } + + $msgs = array(); - // Add fields to the tab - $fields->addFieldToTab("Root.Main", - new HeaderField('VirtualPageHeader',_t('VirtualPage.HEADER', "This is a virtual page")), - "Title" - ); $fields->addFieldToTab("Root.Main", $copyContentFromField, "Title"); // Create links back to the original object in the CMS if($this->CopyContentFrom()->exists()) { - $linkToContent = "CopyContentFromID\">" . - _t('VirtualPage.EDITCONTENT', 'click here to edit the content') . ""; - $fields->addFieldToTab("Root.Main", - $linkToContentLabelField = new LabelField('VirtualPageContentLinkLabel', $linkToContent), - "Title" + $link = "CopyContentFromID\">" + . _t('VirtualPage.EditLink', 'edit') + . ""; + $msgs[] = _t( + 'VirtualPage.HEADERWITHLINK', + "This is a virtual page copying content from \"{title}\" ({link})", + array( + 'title' => $this->CopyContentFrom()->Title, + 'link' => $link + ) + ); + } else { + $msgs[] = _t('VirtualPage.HEADER', "This is a virtual page"); + $msgs[] = _t( + 'SITETREE.VIRTUALPAGEWARNING', + 'Please choose a linked page and save first in order to publish this page' ); - $linkToContentLabelField->setAllowHTML(true); } + if( + $this->CopyContentFromID + && !Versioned::get_versionnumber_by_stage('SiteTree', 'Live', $this->CopyContentFromID) + ) { + $msgs[] = _t( + 'SITETREE.VIRTUALPAGEDRAFTWARNING', + 'Please publish the linked page in order to publish the virtual page' + ); + } + + $fields->addFieldToTab("Root.Main", + new LiteralField( + 'VirtualPageMessage', + '
' . implode('. ', $msgs) . '.
' + ), + 'CopyContentFromID' + ); return $fields; } + + public function getSettingsFields() { + $fields = parent::getSettingsFields(); + if(!$this->CopyContentFrom()->exists()) { + $fields->addFieldToTab("Root.Settings", + new LiteralField( + 'VirtualPageWarning', + '
' + . _t( + 'SITETREE.VIRTUALPAGEWARNINGSETTINGS', + 'Please choose a linked page in the main content fields in order to publish' + ) + . '
' + ), + 'ClassName' + ); + } + + return $fields; + } /** * We have to change it to copy all the content from the original page first. diff --git a/lang/en.yml b/lang/en.yml index acf244fe..f0cda7bf 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -395,9 +395,9 @@ en: CANACCESS: 'You can access the archived site at this link:' HAVEASKED: 'You have asked to view the content of our site on' VirtualPage: - CHOOSE: 'Choose a page to link to' + CHOOSE: 'Linked Page' DESCRIPTION: 'Displays the content of another page' - EDITCONTENT: 'click here to edit the content' + EDITCONTENT: 'Edit content on linked page' HEADER: 'This is a virtual page' PLURALNAME: 'Virtual Pags' PageTypNotAllowedOnRoot: 'Original page type "{type}" is not allowed on the root level for this virtual page'