Skip to content

Commit

Permalink
API Remove CMSEditLink implementation, rely on superclass instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Aug 22, 2024
1 parent e58c388 commit 9b0ec71
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 33 deletions.
14 changes: 7 additions & 7 deletions code/Controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ private function buildEditFormBreadcrumb(ArrayList $items, SiteTree $page, bool
$this->pushCrumb(
$items,
$ancestor->getMenuTitle(),
$unlinked ? false : $ancestor->CMSEditLink()
$unlinked ? false : $ancestor->getCMSEditLink()
);
}
}
Expand All @@ -1109,13 +1109,13 @@ private function buildListViewBreadcrumb(ArrayList $items, SiteTree $page): void
// Find all ancestors of the provided page
$ancestors = $page->getAncestors(true);
$ancestors = array_reverse($ancestors->toArray() ?? []);

//turns the title and link of the breadcrumbs into template-friendly variables
$params = array_filter([
'view' => $this->getRequest()->getVar('view'),
'q' => $this->getRequest()->getVar('q')
]);

foreach ($ancestors as $ancestor) {
// Link back to the list view for the current ancestor
$params['ParentID'] = $ancestor->ID;
Expand Down Expand Up @@ -1710,7 +1710,7 @@ public function ListViewForm()
/** @var SiteTree $item */
$title = sprintf(
'<a class="action-detail" href="%s">%s</a>',
$item->CMSEditLink(),
$item->getCMSEditLink(),
$item->TreeTitle // returns HTML, does its own escaping
);
$breadcrumbs = $item->Breadcrumbs(20, true, false, true, '/');
Expand Down Expand Up @@ -2103,7 +2103,7 @@ public function doRollback($data, $form)
// Can be used in different contexts: In normal page edit view, in which case the redirect won't have any effect.
// Or in history view, in which case a revert causes the CMS to re-load the edit view.
// The X-Pjax header forces a "full" content refresh on redirect.
$url = $record->CMSEditLink();
$url = $record->getCMSEditLink();
$this->getResponse()->addHeader('X-ControllerURL', $url);
$this->getRequest()->addHeader('X-Pjax', 'Content');
$this->getResponse()->addHeader('X-Pjax', 'Content');
Expand Down Expand Up @@ -2220,7 +2220,7 @@ public function duplicate(HTTPRequest $request): HTTPResponse
['title' => $newPage->Title]
) ?? '')
);
$url = $newPage->CMSEditLink();
$url = $newPage->getCMSEditLink();
$this->getResponse()->addHeader('X-ControllerURL', $url);
$this->getRequest()->addHeader('X-Pjax', 'Content');
$this->getResponse()->addHeader('X-Pjax', 'Content');
Expand Down Expand Up @@ -2256,7 +2256,7 @@ public function duplicatewithchildren(HTTPRequest $request): HTTPResponse
['title' => $newPage->Title]
) ?? '')
);
$url = $newPage->CMSEditLink();
$url = $newPage->getCMSEditLink();
$this->getResponse()->addHeader('X-ControllerURL', $url);
$this->getRequest()->addHeader('X-Pjax', 'Content');
$this->getResponse()->addHeader('X-Pjax', 'Content');
Expand Down
4 changes: 2 additions & 2 deletions code/Controllers/SilverStripeNavigatorItem_CMSLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getHTML()
{
return sprintf(
'<a href="%s">%s</a>',
$this->record->CMSEditLink(),
$this->record->getCMSEditLink(),
_t('SilverStripe\\CMS\\Controllers\\ContentController.CMS', 'CMS')
);
}
Expand All @@ -28,7 +28,7 @@ public function getTitle()

public function getLink()
{
return $this->record->CMSEditLink();
return $this->record->getCMSEditLink();
}

public function isActive()
Expand Down
21 changes: 3 additions & 18 deletions code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
'Link' => 'Text',
'RelativeLink' => 'Text',
'AbsoluteLink' => 'Text',
'CMSEditLink' => 'Text',
'TreeTitle' => 'HTMLFragment',
'MetaTags' => 'HTMLFragment',
];
Expand Down Expand Up @@ -758,20 +757,6 @@ public function getAbsoluteLiveLink($includeStageEqualsLive = true)
return $link;
}

/**
* Generates a link to edit this page in the CMS.
*
* Implemented here to satisfy the CMSPreviewable interface, but data is intended to be loaded via Extension
*
* @see SilverStripe\Admin\CMSEditLinkExtension
*
* @return string
*/
public function CMSEditLink()
{
return $this->extend('CMSEditLink')[0] ?? '';
}

/**
* Return a CSS identifier generated from this page's link.
*
Expand Down Expand Up @@ -1504,7 +1489,7 @@ public function MetaComponents()
$tags['cmsEditLink'] = [
'attributes' => [
'name' => 'x-cms-edit-link',
'content' => $this->CMSEditLink(),
'content' => $this->getCMSEditLink(),
],
];
}
Expand Down Expand Up @@ -2157,11 +2142,11 @@ public function getCMSFields()
'Untitled {instanceType}',
['instanceType' => $item->i18n_singular_name()]
);
$tag = $item->hasMethod('CMSEditLink') ? 'a' : 'span';
$tag = $item->hasMethod('getCMSEditLink') ? 'a' : 'span';
return sprintf(
'<%s%s class="dependent-content__edit-link %s">%s</%s>',
$tag,
$tag === 'a' ? sprintf(' href="%s"', $item->CMSEditLink()) : '',
$tag === 'a' ? sprintf(' href="%s"', $item->getCMSEditLink()) : '',
$title ? '' : 'dependent-content__edit-link--untitled',
$title ? Convert::raw2xml($title) : $untitled,
$tag
Expand Down
2 changes: 1 addition & 1 deletion code/Model/VirtualPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function getCMSFields()
'a',
[
'class' => 'cmsEditlink',
'href' => $this->CopyContentFrom()->CMSEditLink(),
'href' => $this->CopyContentFrom()->getCMSEditLink(),
],
_t(VirtualPage::class . '.EditLink', 'edit')
);
Expand Down
8 changes: 4 additions & 4 deletions tests/php/Model/SiteTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ public function testMetaTags()
$this->assertStringContainsString('<meta name="description" content="The &lt;br /&gt; and &lt;br&gt; tags"', $meta);
$this->assertStringContainsString('<link rel="canonical" href="http://www.mysite.com/html-and-xml"', $meta);
$this->assertStringContainsString('<meta name="x-page-id" content="' . $page->ID.'"', $meta);
$this->assertStringContainsString('<meta name="x-cms-edit-link" content="' . $page->CMSEditLink().'"', $meta);
$this->assertStringContainsString('<meta name="x-cms-edit-link" content="' . $page->getCMSEditLink().'"', $meta);
$this->assertStringContainsString('<title>HTML &amp; XML</title>', $meta);

// Test without title
Expand Down Expand Up @@ -1566,7 +1566,7 @@ public function testMetaComponents()
'cmsEditLink' => [
'attributes' => [
'name' => 'x-cms-edit-link',
'content' => $page->CMSEditLink()
'content' => $page->getCMSEditLink()
]
]
];
Expand Down Expand Up @@ -2084,11 +2084,11 @@ public function testCMSEditLink()
$child = $this->objFromFixture(BelongsToPage::class, 'one');
$this->assertSame(
"http://localhost/admin/pages/edit/show/$page->ID",
$page->CMSEditLink()
$page->getCMSEditLink()
);
$this->assertSame(
"http://localhost/admin/pages/edit/show/$page->ID/field/ChildObjects/item/$child->ID",
$child->CMSEditLink()
$child->getCMSEditLink()
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/php/Model/VirtualPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testMetaTags()
$this->assertStringContainsString('<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'"', $meta);
$this->assertStringContainsString('<link rel="canonical" href="'.$master->AbsoluteLink().'"', $meta);
$this->assertStringContainsString('<meta name="x-page-id" content="'.$vp1->ID.'"', $meta);
$this->assertStringContainsString('<meta name="x-cms-edit-link" content="'.$vp1->CMSEditLink().'"', $meta);
$this->assertStringContainsString('<meta name="x-cms-edit-link" content="'.$vp1->getCMSEditLink().'"', $meta);
$this->assertStringContainsString('<title>'.$master->Title.'</title>', $meta);
}

Expand Down

0 comments on commit 9b0ec71

Please sign in to comment.