Skip to content

Commit

Permalink
Merge pull request #683 from chillu/pulls/virtualpage-1594
Browse files Browse the repository at this point in the history
Better UI feedback on VirtualPage states (fixes #1594)
  • Loading branch information
chillu committed Apr 18, 2013
2 parents c6d6e24 + 878cf54 commit c922d08
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
68 changes: 56 additions & 12 deletions code/model/VirtualPage.php
Expand Up @@ -170,7 +170,7 @@ public function getCMSFields() {
// 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
Expand All @@ -184,27 +184,71 @@ public function getCMSFields() {
$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 = "<a class=\"cmsEditlink\" href=\"admin/pages/edit/show/$this->CopyContentFromID\">" .
_t('VirtualPage.EDITCONTENT', 'click here to edit the content') . "</a>";
$fields->addFieldToTab("Root.Main",
$linkToContentLabelField = new LabelField('VirtualPageContentLinkLabel', $linkToContent),
"Title"
$link = "<a class=\"cmsEditlink\" href=\"admin/pages/edit/show/$this->CopyContentFromID\">"
. _t('VirtualPage.EditLink', 'edit')
. "</a>";
$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',
'<div class="message notice">' . implode('. ', $msgs) . '.</div>'
),
'CopyContentFromID'
);

return $fields;
}

public function getSettingsFields() {
$fields = parent::getSettingsFields();
if(!$this->CopyContentFrom()->exists()) {
$fields->addFieldToTab("Root.Settings",
new LiteralField(
'VirtualPageWarning',
'<div class="message notice">'
. _t(
'SITETREE.VIRTUALPAGEWARNINGSETTINGS',
'Please choose a linked page in the main content fields in order to publish'
)
. '</div>'
),
'ClassName'
);
}

return $fields;
}

/**
* We have to change it to copy all the content from the original page first.
Expand Down
4 changes: 2 additions & 2 deletions lang/en.yml
Expand Up @@ -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'
Expand Down

0 comments on commit c922d08

Please sign in to comment.