Merge remote-tracking branch 'origin/master' into translation-staging

This commit is contained in:
Ingo Schommer 2012-07-18 15:15:44 +02:00
commit 4fd22385d7
21 changed files with 155 additions and 206 deletions

View File

@ -318,7 +318,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// The root element should point to the pages tree view,
// rather than the actual controller (which would just show an empty edit form)
$items[0]->Title = self::menu_title_for_class('CMSPagesController');
$defaultTitle = self::menu_title_for_class('CMSPagesController');
$items[0]->Title = _t("{$this->class}.MENUTITLE", $defaultTitle);
$items[0]->Link = singleton('CMSPagesController')->Link();
return $items;
@ -607,7 +608,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$form->addExtraClass('cms-edit-form');
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
// TODO Can't merge $FormAttributes in template at the moment
$form->addExtraClass('center ss-tabset ' . $this->BaseCSSClasses());
$form->addExtraClass('center ' . $this->BaseCSSClasses());
// if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
$form->setAttribute('data-pjax-fragment', 'CurrentForm');
@ -715,7 +716,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
}
},
'getTreeTitle' => function($value, &$item) use($controller) {
return '<a class="cms-panel-link" href="' . $controller->Link('show') . '/' . $item->ID . '">' . $item->TreeTitle . '</a>';
return '<a class="action-detail" href="' . singleton('CMSPageEditController')->Link('show') . '/' . $item->ID . '">' . $item->TreeTitle . '</a>';
}
));

View File

@ -5,6 +5,15 @@ class CMSSettingsController extends LeftAndMain {
static $url_rule = '/$Action/$ID/$OtherID';
static $menu_priority = -1;
static $menu_title = 'Settings';
public function getResponseNegotiator() {
$neg = parent::getResponseNegotiator();
$controller = $this;
$neg->setCallback('CurrentForm', function() use(&$controller) {
return $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
});
return $neg;
}
/**
* @return Form
@ -16,8 +25,8 @@ class CMSSettingsController extends LeftAndMain {
$actions = $siteConfig->getCMSActions();
$form = new Form($this, 'EditForm', $fields, $actions);
$form->addExtraClass('root-form');
$form->addExtraClass('cms-edit-form cms-panel-padded center');
// don't add data-pjax-fragment=CurrentForm, its added in the content template instead
if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
$form->setHTMLID('Form_EditForm');
@ -47,8 +56,7 @@ class CMSSettingsController extends LeftAndMain {
$siteConfig->write();
$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'Saved.')));
return $form->forTemplate();
return $this->getResponseNegotiator()->respond($this->request);
}
function LinkPreview() {
@ -56,9 +64,10 @@ class CMSSettingsController extends LeftAndMain {
}
function Breadcrumbs($unlinked = false) {
$defaultTitle = self::menu_title_for_class(get_class($this));
return new ArrayList(array(
new ArrayData(array(
'Title' => $this->SectionTitle(),
'Title' => _t("{$this->class}.MENUTITLE", $defaultTitle),
'Link' => false
))
));

View File

@ -51,6 +51,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider {
// Always block the HtmlEditorField.js otherwise it will be sent with an ajax request
Requirements::block(FRAMEWORK_DIR . '/javascript/HtmlEditorField.js');
Requirements::javascript(CMS_DIR . '/javascript/ReportAdmin.js');
}
/**
@ -147,48 +148,12 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider {
}
public function getEditForm($id = null, $fields = null) {
$fields = new FieldList();
$report = $this->reportObject;
if($report) {
// List all reports
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(),
new GridFieldPrintButton(),
new GridFieldExportButton()
);
$gridField = new GridField('Report',$report->title(), $report->sourceRecords(array(), null, null), $gridFieldConfig);
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
$displayFields = array();
$fieldCasting = array();
$fieldFormatting = array();
// Parse the column information
foreach($report->columns() as $source => $info) {
if(is_string($info)) $info = array('title' => $info);
if(isset($info['formatting'])) $fieldFormatting[$source] = $info['formatting'];
if(isset($info['csvFormatting'])) $csvFieldFormatting[$source] = $info['csvFormatting'];
if(isset($info['casting'])) $fieldCasting[$source] = $info['casting'];
if(isset($info['link']) && $info['link']) {
$link = singleton('CMSPageEditController')->Link('show');
$fieldFormatting[$source] = '<a href=\"' . $link . '/$ID\">$value</a>';
}
$displayFields[$source] = isset($info['title']) ? $info['title'] : $source;
}
$columns->setDisplayFields($displayFields);
$columns->setFieldCasting($fieldCasting);
$columns->setFieldFormatting($fieldFormatting);
$fields->push($gridField);
$fields = $report->getCMSFields();
} else {
// List all reports
$fields = new FieldList();
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldSortableHeader(),
@ -210,6 +175,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider {
$actions = new FieldList();
$form = new Form($this, "EditForm", $fields, $actions);
$form->addExtraClass('cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses());
$form->loadDataFrom($this->request->getVars());
$this->extend('updateEditForm', $form);

View File

@ -1854,10 +1854,14 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$urlsegment,
new TextField("MenuTitle", $this->fieldLabel('MenuTitle')),
$htmlField = new HtmlEditorField("Content", _t('SiteTree.HTMLEDITORTITLE', "Content", 'HTML editor title')),
new TextField("MetaTitle", $this->fieldLabel('MetaTitle')),
new TextareaField("MetaKeywords", $this->fieldLabel('MetaKeywords'), 1),
new TextareaField("MetaDescription", $this->fieldLabel('MetaDescription')),
new TextareaField("ExtraMeta",$this->fieldLabel('ExtraMeta'))
ToggleCompositeField::create('Metadata', _t('SiteTree.MetadataToggle', 'Metadata'),
array(
new TextField("MetaTitle", $this->fieldLabel('MetaTitle')),
new TextareaField("MetaKeywords", $this->fieldLabel('MetaKeywords'), 1),
new TextareaField("MetaDescription", $this->fieldLabel('MetaDescription')),
new TextareaField("ExtraMeta",$this->fieldLabel('ExtraMeta'))
)
)->setHeadingLevel(4)
),
$tabDependent = new Tab('Dependent',
$dependentNote,
@ -2329,7 +2333,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$result = array();
foreach($classes as $class) {
$instance = singleton($class);
if((($instance instanceof HiddenClass) || !$instance->canCreate())) continue;
// if the current page type is this the same as the class type always show the page type in the list see open ticket 5880 for why
if ($this->ClassName != $instance->ClassName) {
if((($instance instanceof HiddenClass) || !$instance->canCreate())) continue;
}
if($perms = $instance->stat('need_permission')) {
if(!$this->can($perms)) continue;
@ -2730,4 +2738,4 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
self::$cache_permissions = array();
}
}
}

View File

@ -80,11 +80,12 @@ class BrokenLinksReport extends SS_Report {
$dateTitle = _t('BrokenLinksReport.ColumnDateLastPublished', 'Date last published');
}
$linkBase = singleton('CMSPageEditController')->Link('show') . '/';
$fields = array(
"Title" => array(
"title" => _t('BrokenLinksReport.PageName', 'Page name'),
'formatting' => sprintf(
'<a href=\"admin/show/$ID\" title=\"%s\">$value</a>',
'<a href=\"' . $linkBase . '$ID\" title=\"%s\">$value</a>',
_t('BrokenLinksReport.HoverTitleEditPage', 'Edit page')
)
),
@ -97,7 +98,15 @@ class BrokenLinksReport extends SS_Report {
),
'AbsoluteLink' => array(
'title' => _t('BrokenLinksReport.ColumnURL', 'URL'),
'formatting' => '$value " . ($AbsoluteLiveLink ? "<a target=\"_blank\" href=\"$AbsoluteLiveLink\">(live)</a>" : "") . " <a target=\"_blank\" href=\"$value?stage=Stage\">(draft)</a>'
'formatting' => function($value, $item) {
$liveLink = $item->AbsoluteLiveLink;
$stageLink = $item->AbsoluteLink();
return sprintf('%s <a href="%s">%s</a>',
$stageLink,
$liveLink ? $liveLink : $stageLink . '?stage=Stage',
$liveLink ? '(live)' : '(draft)'
);
}
)
);

View File

@ -97,8 +97,7 @@ class SS_Report extends ViewableData {
*/
function sourceQuery($params) {
if($this->hasMethod('sourceRecords')) {
$query = new SS_Report_FakeQuery($this, 'sourceRecords', $params);
return $query;
return $this->sourceRecords()->dataQuery();
} else {
user_error("Please override sourceQuery()/sourceRecords() and columns() or, if necessary, override getReportField()", E_USER_ERROR);
}
@ -108,14 +107,20 @@ class SS_Report extends ViewableData {
* Return a SS_List records for this report.
*/
function records($params) {
if($this->hasMethod('sourceRecords')) return $this->sourceRecords($params, null, null);
else {
if($this->hasMethod('sourceRecords')) {
return $this->sourceRecords($params, null, null);
} else {
$query = $this->sourceQuery();
return singleton($this->dataClass())->buildDataObjectSet($query->execute(), "DataObjectSet", $query);
$results = new ArrayList();
foreach($query->execute() as $data) {
$class = $this->dataClass();
$result = new $class($data);
$results->push($result);
}
return $results;
}
}
/**
* Return the data class for this report
*/
@ -132,8 +137,6 @@ class SS_Report extends ViewableData {
);
}
/**
* @deprecated 3.0
* All subclasses of SS_Report now appear in the report admin, no need to register or unregister.
@ -171,7 +174,6 @@ class SS_Report extends ViewableData {
}
}
/**
* Return an array of excluded reports. That is, reports that will not be included in
* the list of reports in report admin in the CMS.
@ -225,31 +227,31 @@ class SS_Report extends ViewableData {
* @return FieldList
*/
function getCMSFields() {
$fields = new FieldList(
new LiteralField(
'ReportTitle',
"<h3>{$this->title()}</h3>"
)
);
$fields = new FieldList();
if($title = $this->title()) {
$fields->push(new LiteralField('ReportTitle', "<h3>{$title}</h3>"));
}
if($this->description()) $fields->push(
new LiteralField('ReportDescription', "<p>" . $this->description() . "</p>"));
if($description = $this->description()) {
$fields->push(new LiteralField('ReportDescription', "<p>" . $description . "</p>"));
}
// Add search fields is available
if($params = $this->parameterFields()) {
$filters = new FieldGroup('Filters');
foreach($params as $param) {
if ($param instanceof HiddenField) $fields->push($param);
else $filters->push($param);
if($this->hasMethod('parameterFields') && $fields = $this->parameterFields()) {
foreach($fields as $field) {
// Namespace fields for easier handling in form submissions
$field->setName(sprintf('filters[%s]', $field->getName()));
$field->addExtraClass('no-change-track'); // ignore in changetracker
$fields->push($field);
}
$fields->push($filters);
// Add a search button
$fields->push(new FormAction('updatereport', 'Filter'));
$fields->push(new FormAction('updatereport', _t('GridField.Filter')));
}
$fields->push($this->getReportField());
$this->extend('updateCMSFields', $fields);
return $fields;
@ -263,7 +265,7 @@ class SS_Report extends ViewableData {
}
/**
* Return a field, such as a {@link ComplexTableField} that is
* Return a field, such as a {@link GridField} that is
* used to show and manipulate data relating to this report.
*
* Generally, you should override {@link columns()} and {@link records()} to make your report,
@ -272,11 +274,24 @@ class SS_Report extends ViewableData {
* @return FormField subclass
*/
function getReportField() {
$columnTitles = array();
$fieldFormatting = array();
$csvFieldFormatting = array();
// TODO Remove coupling with global state
$params = isset($_REQUEST['filters']) ? $_REQUEST['filters'] : array();
$items = $this->sourceRecords($params, null, null);
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(),
new GridFieldPrintButton(),
new GridFieldExportButton()
);
$gridField = new GridField('Report',$this->title(), $items, $gridFieldConfig);
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
$displayFields = array();
$fieldCasting = array();
$fieldFormatting = array();
// Parse the column information
foreach($this->columns() as $source => $info) {
if(is_string($info)) $info = array('title' => $info);
@ -284,28 +299,19 @@ class SS_Report extends ViewableData {
if(isset($info['formatting'])) $fieldFormatting[$source] = $info['formatting'];
if(isset($info['csvFormatting'])) $csvFieldFormatting[$source] = $info['csvFormatting'];
if(isset($info['casting'])) $fieldCasting[$source] = $info['casting'];
$columnTitles[$source] = isset($info['title']) ? $info['title'] : $source;
}
// To do: implement pagination
$query = $this->sourceQuery($_REQUEST);
$tlf = new TableListField('ReportContent', $this->dataClass(), $columnTitles);
$tlf->setCustomQuery($query);
$tlf->setShowPagination(true);
$tlf->setPageSize(50);
$tlf->setPermissions(array('export', 'print'));
// Hack to figure out if we are printing
if (isset($_REQUEST['url']) && array_pop(explode('/', $_REQUEST['url'])) == 'printall') {
$tlf->setTemplate('SSReportTableField');
}
if($fieldFormatting) $tlf->setFieldFormatting($fieldFormatting);
if($csvFieldFormatting) $tlf->setCSVFieldFormatting($csvFieldFormatting);
if($fieldCasting) $tlf->setFieldCasting($fieldCasting);
return $tlf;
if(isset($info['link']) && $info['link']) {
$link = singleton('CMSPageEditController')->Link('show');
$fieldFormatting[$source] = '<a href=\"' . $link . '/$ID\">$value</a>';
}
$displayFields[$source] = isset($info['title']) ? $info['title'] : $source;
}
$columns->setDisplayFields($displayFields);
$columns->setFieldCasting($fieldCasting);
$columns->setFieldFormatting($fieldFormatting);
return $gridField;
}
/**
@ -332,76 +338,7 @@ class SS_Report extends ViewableData {
function TreeTitle() {
return $this->title();
}
}
/**
* This is an object that can be used to dress up a more complex querying mechanism in the clothing
* of a SQLQuery object. This means that you can inject it into a TableListField.
*
* Use it like this:
*
* function sourceQuery($params) {
* return new SS_Report_FakeQuery($this, 'sourceRecords', $params)
* }
* function sourceRecords($params, $sort, $limit) {
* // Do some stuff
* // Return a SS_List of actual objects.
* }
*
* This object is used by the default implementation of sourceQuery() on SS_Report, to make use of
* a sourceReords() method if one exists.
*/
class SS_Report_FakeQuery extends SQLQuery {
public $orderby;
public $limit;
protected $obj, $method, $params;
function __construct($obj, $method, $params) {
$this->obj = $obj;
$this->method = $method;
$this->params = $params;
}
/**
* Provide a method that will return a list of columns that can be used to sort.
*/
function setSortColumnMethod($sortColMethod) {
$this->sortColMethod = $sortColMethod;
}
function limit($limit, $offset = 0) {
$this->limit = $limit;
}
function unlimitedRowCount($column = null) {
$source = $this->obj->{$this->method}($this->params, null, null);
return $source ? $source->Count() : 0;
}
function execute() {
$output = array();
$source = $this->obj->{$this->method}($this->params, $this->orderby, $this->limit);
if($source) foreach($source as $item) {
$mapItem = $item->toMap();
$mapItem['RecordClassName'] = get_class($item);
$output[] = $mapItem;
}
return $output;
}
function canSortBy($fieldName) {
$fieldName = preg_replace('/(\s+?)(A|DE)SC$/', '', $fieldName);
if($this->sortColMethod) {
$columns = $this->obj->{$this->sortColMethod}();
return in_array($fieldName, $columns);
} else {
return false;
}
}
}
/**

View File

@ -92,7 +92,8 @@ class SideReportView extends ViewableData {
}
if(isset($info['link']) && $info['link']) {
$link = ($info['link'] === true) ? "admin/show/$record->ID" : $info['link'];
$linkBase = singleton('CMSPageEditController')->Link('show') . '/';
$link = ($info['link'] === true) ? $linkBase . $record->ID : $info['link'];
return $prefix . "<a $classClause href=\"$link\">$val</a>";
} else {
return $prefix . "<span $classClause>$val</span>";

18
javascript/ReportAdmin.js Normal file
View File

@ -0,0 +1,18 @@
/**
* File: ReportAdmin.js
*/
(function($) {
$.entwine('ss', function($){
$('.ReportAdmin .cms-edit-form').entwine({
onsubmit: function(e) {
var url = document.location.href, params = this.find(':input[name^=filters]').serializeArray();
params = $.grep(params, function(param) {return (param.value);}); // filter out empty
if(params) url = $.path.addSearchParams(url, params);
$('.cms-container').loadPanel(url);
return false;
}
});
});
})(jQuery);

View File

@ -26,7 +26,7 @@ class MigrateSiteTreeLinkingTask extends BuildTask {
// TOOD: Replace in all HTMLText fields
$page->Content = preg_replace (
"/href *= *([\"']?){$linked->URLSegment}\/?/i",
"href=$1[sitetree_link id={$linked->ID}]",
"href=$1[sitetree_link,id={$linked->ID}]",
$page->Content,
-1,
$replaced

View File

@ -1,4 +1,4 @@
<div class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
<div id="assetadmin-cms-content" class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
<% with EditForm %>
<div class="cms-content-header north">

View File

@ -1,4 +1,4 @@
<div class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
<div id="assetadmin-cms-content" class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
<div class="cms-content-header north">
<div class="cms-content-header-info">

View File

@ -1,4 +1,4 @@
<div id="pages-controller-cms-content" class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
<div id="pages-controller-cms-content" class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content" data-ignore-tab-state="true">
<div class="cms-content-header north">
<div class="cms-content-header-info">

View File

@ -1,4 +1,4 @@
<div class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
<div id="settings-controller-cms-content" class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content CurrentForm">
<div class="cms-content-header north">
<% with EditForm %>

View File

@ -1,4 +1,4 @@
<div class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
<div id="reportadmin-cms-content" class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content">
<div class="cms-content-header north">
<% with EditForm %>

View File

@ -112,7 +112,7 @@ class ContentControllerTest extends FunctionalTest {
$page = new SiteTree();
$page->URLSegment = 'linking-page';
$page->Content = sprintf('<a href="[sitetree_link id=%s]">Testlink</a>', $linkedPage->ID);
$page->Content = sprintf('<a href="[sitetree_link,id=%s]">Testlink</a>', $linkedPage->ID);
$page->write();
$page->publish('Stage', 'Live');

View File

@ -36,7 +36,7 @@ class SiteTreeBacklinksTest extends SapphireTest {
$this->assertNotContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 doesn\'t exist');
// add hyperlink to page 1 on page 2
$page2->Content .= '<p><a href="[sitetree_link id='.$page1->ID.']">Testing page 1 link</a></p>';
$page2->Content .= '<p><a href="[sitetree_link,id='.$page1->ID.']">Testing page 1 link</a></p>';
$page2->write();
// load page 1
@ -205,7 +205,7 @@ class SiteTreeBacklinksTest extends SapphireTest {
$this->assertNotContains($page2->ID, $page1->BackLinkTracking()->column('ID'), 'Assert backlink to page 2 doesn\'t exist');
// add hyperlink to page 1 on page 2
$page2->ExtraContent .= '<p><a href="[sitetree_link id='.$page1->ID.']">Testing page 1 link</a></p>';
$page2->ExtraContent .= '<p><a href="[sitetree_link,id='.$page1->ID.']">Testing page 1 link</a></p>';
$page2->write();
$page2->doPublish();

View File

@ -11,7 +11,7 @@ Page:
page3:
Title: page3
URLSegment: page3
Content: '<p><a href="[sitetree_link id=1]">Testing page 1 link</a></p>'
Content: '<p><a href="[sitetree_link,id=1]">Testing page 1 link</a></p>'
LinkTracking: =>Page.page1

View File

@ -21,11 +21,11 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
function testBrokenLinksBetweenPages() {
$obj = $this->objFromFixture('Page','content');
$obj->Content = '<a href="[sitetree_link id=3423423]">this is a broken link</a>';
$obj->Content = '<a href="[sitetree_link,id=3423423]">this is a broken link</a>';
$obj->syncLinkTracking();
$this->assertTrue($obj->HasBrokenLink, 'Page has a broken link');
$obj->Content = '<a href="[sitetree_link id=' . $this->idFromFixture('Page','about') .']">this is not a broken link</a>';
$obj->Content = '<a href="[sitetree_link,id=' . $this->idFromFixture('Page','about') .']">this is not a broken link</a>';
$obj->syncLinkTracking();
$this->assertFalse($obj->HasBrokenLink, 'Page does NOT have a broken link');
}
@ -107,7 +107,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
$linkDest->doPublish();
$linkSrc = $this->objFromFixture('Page','content');
$linkSrc->Content = "<p><a href=\"[sitetree_link id=$linkDest->ID]\">about us</a></p>";
$linkSrc->Content = "<p><a href=\"[sitetree_link,id=$linkDest->ID]\">about us</a></p>";
$linkSrc->write();
$linkSrc->doPublish();
@ -151,7 +151,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
$linkDest->doDeleteFromLive();
$linkSrc = $this->objFromFixture('Page','content');
$linkSrc->Content = "<p><a href=\"[sitetree_link id=$linkDest->ID]\">about us</a></p>";
$linkSrc->Content = "<p><a href=\"[sitetree_link,id=$linkDest->ID]\">about us</a></p>";
$linkSrc->write();
// Publish the source of the link, while the dest is still unpublished.
@ -175,7 +175,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
// Content links are one kind of link to pages
$p2 = new Page();
$p2->Title = "regular link";
$p2->Content = "<a href=\"[sitetree_link id=$p->ID]\">test</a>";
$p2->Content = "<a href=\"[sitetree_link,id=$p->ID]\">test</a>";
$p2->write();
$this->assertTrue($p2->doPublish());
@ -250,7 +250,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest {
// Content links are one kind of link to pages
$p2 = new Page();
$p2->Title = "regular link";
$p2->Content = "<a href=\"[sitetree_link id=$p->ID]\">test</a>";
$p2->Content = "<a href=\"[sitetree_link,id=$p->ID]\">test</a>";
$p2->write();
$this->assertTrue($p2->doPublish());

View File

@ -11,12 +11,12 @@ class SiteTreeHtmlEditorFieldTest extends FunctionalTest {
$aboutID = $this->idFromFixture('SiteTree', 'about');
$contactID = $this->idFromFixture('SiteTree', 'contact');
$editor->setValue("<a href=\"[sitetree_link id=$aboutID]\">Example Link</a>");
$editor->setValue("<a href=\"[sitetree_link,id=$aboutID]\">Example Link</a>");
$editor->saveInto($sitetree);
$this->assertEquals(array($aboutID => $aboutID), $sitetree->LinkTracking()->getIdList(), 'Basic link tracking works.');
$editor->setValue (
"<a href=\"[sitetree_link id=$aboutID]\"></a><a href=\"[sitetree_link id=$contactID]\"></a>"
"<a href=\"[sitetree_link,id=$aboutID]\"></a><a href=\"[sitetree_link,id=$contactID]\"></a>"
);
$editor->saveInto($sitetree);
$this->assertEquals (
@ -89,13 +89,13 @@ class SiteTreeHtmlEditorFieldTest extends FunctionalTest {
$this->assertFalse((bool) $sitetree->HasBrokenLink);
$editor->setValue('<p><a href="[sitetree_link id=0]">Broken Link</a></p>');
$editor->setValue('<p><a href="[sitetree_link,id=0]">Broken Link</a></p>');
$editor->saveInto($sitetree);
$this->assertTrue($sitetree->HasBrokenLink);
$editor->setValue(sprintf (
'<p><a href="[sitetree_link id=%d]">Working Link</a></p>',
'<p><a href="[sitetree_link,id=%d]">Working Link</a></p>',
$this->idFromFixture('SiteTree', 'home')
));
$sitetree->HasBrokenLink = false;
@ -108,13 +108,13 @@ class SiteTreeHtmlEditorFieldTest extends FunctionalTest {
$sitetree = new SiteTree();
$editor = new HtmlEditorField('Content');
$editor->setValue('<a href="[sitetree_link id=0]">Broken Link</a>');
$editor->setValue('<a href="[sitetree_link,id=0]">Broken Link</a>');
$element = new SimpleXMLElement(html_entity_decode((string) new SimpleXMLElement($editor->Field())));
$this->assertContains('ss-broken', (string) $element['class'], 'A broken link class is added to broken links');
$editor->setValue(sprintf (
'<a href="[sitetree_link id=%d]">Working Link</a>',
'<a href="[sitetree_link,id=%d]">Working Link</a>',
$this->idFromFixture('SiteTree', 'home')
));

View File

@ -587,8 +587,8 @@ class SiteTreeTest extends SapphireTest {
$parser = new ShortcodeParser();
$parser->register('sitetree_link', array('SiteTree', 'link_shortcode_handler'));
$aboutShortcode = sprintf('[sitetree_link id=%d]', $aboutPage->ID);
$aboutEnclosed = sprintf('[sitetree_link id=%d]Example Content[/sitetree_link]', $aboutPage->ID);
$aboutShortcode = sprintf('[sitetree_link,id=%d]', $aboutPage->ID);
$aboutEnclosed = sprintf('[sitetree_link,id=%d]Example Content[/sitetree_link]', $aboutPage->ID);
$aboutShortcodeExpected = $aboutPage->Link();
$aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $aboutPage->Link());
@ -601,8 +601,8 @@ class SiteTreeTest extends SapphireTest {
$this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test that deleted pages still link.');
$this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed));
$aboutShortcode = '[sitetree_link id="-1"]';
$aboutEnclosed = '[sitetree_link id="-1"]Example Content[/sitetree_link]';
$aboutShortcode = '[sitetree_link,id="-1"]';
$aboutEnclosed = '[sitetree_link,id="-1"]Example Content[/sitetree_link]';
$aboutShortcodeExpected = $errorPage->Link();
$aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $errorPage->Link());
@ -611,7 +611,7 @@ class SiteTreeTest extends SapphireTest {
$this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed));
$this->assertEquals('', $parser->parse('[sitetree_link]'), 'Test that invalid ID attributes are not parsed.');
$this->assertEquals('', $parser->parse('[sitetree_link id="text"]'));
$this->assertEquals('', $parser->parse('[sitetree_link,id="text"]'));
$this->assertEquals('', $parser->parse('[sitetree_link]Example Content[/sitetree_link]'));
}

View File

@ -29,25 +29,25 @@ class MigrateSiteTreeLinkingTaskTest extends SapphireTest {
$hashID = $this->idFromFixture('SiteTree', 'hash_link');
$homeContent = sprintf (
'<a href="[sitetree_link id=%d]">About</a><a href="[sitetree_link id=%d]">Staff</a><a href="http://silverstripe.org/">External Link</a>',
'<a href="[sitetree_link,id=%d]">About</a><a href="[sitetree_link,id=%d]">Staff</a><a href="http://silverstripe.org/">External Link</a>',
$aboutID,
$staffID
);
$aboutContent = sprintf (
'<a href="[sitetree_link id=%d]">Home</a><a href="[sitetree_link id=%d]">Staff</a>',
'<a href="[sitetree_link,id=%d]">Home</a><a href="[sitetree_link,id=%d]">Staff</a>',
$homeID,
$staffID
);
$staffContent = sprintf (
'<a href="[sitetree_link id=%d]">Home</a><a href="[sitetree_link id=%d]">About</a>',
'<a href="[sitetree_link,id=%d]">Home</a><a href="[sitetree_link,id=%d]">About</a>',
$homeID,
$aboutID
);
$actionContent = sprintf (
'<a href="[sitetree_link id=%d]SearchForm">Search Form</a>', $homeID
'<a href="[sitetree_link,id=%d]SearchForm">Search Form</a>', $homeID
);
$hashLinkContent = sprintf (
'<a href="[sitetree_link id=%d]#anchor">Home</a><a href="[sitetree_link id=%d]#second-anchor">About</a>',
'<a href="[sitetree_link,id=%d]#anchor">Home</a><a href="[sitetree_link,id=%d]#second-anchor">About</a>',
$homeID,
$aboutID
);