API Remove CMSEditLink implementation, rely on superclass instead. (#2987)

This commit is contained in:
Guy Sartorelli 2024-08-26 09:58:26 +12:00 committed by GitHub
parent 0dd216da90
commit fccdeb1757
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 16 additions and 31 deletions

View File

@ -1096,7 +1096,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$this->pushCrumb( $this->pushCrumb(
$items, $items,
$ancestor->getMenuTitle(), $ancestor->getMenuTitle(),
$unlinked ? false : $ancestor->CMSEditLink() $unlinked ? false : $ancestor->getCMSEditLink()
); );
} }
} }
@ -1710,7 +1710,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
/** @var SiteTree $item */ /** @var SiteTree $item */
$title = sprintf( $title = sprintf(
'<a class="action-detail" href="%s">%s</a>', '<a class="action-detail" href="%s">%s</a>',
$item->CMSEditLink(), $item->getCMSEditLink(),
$item->TreeTitle // returns HTML, does its own escaping $item->TreeTitle // returns HTML, does its own escaping
); );
$breadcrumbs = $item->Breadcrumbs(20, true, false, true, '/'); $breadcrumbs = $item->Breadcrumbs(20, true, false, true, '/');
@ -2103,7 +2103,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Can be used in different contexts: In normal page edit view, in which case the redirect won't have any effect. // 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. // 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. // The X-Pjax header forces a "full" content refresh on redirect.
$url = $record->CMSEditLink(); $url = $record->getCMSEditLink();
$this->getResponse()->addHeader('X-ControllerURL', $url); $this->getResponse()->addHeader('X-ControllerURL', $url);
$this->getRequest()->addHeader('X-Pjax', 'Content'); $this->getRequest()->addHeader('X-Pjax', 'Content');
$this->getResponse()->addHeader('X-Pjax', 'Content'); $this->getResponse()->addHeader('X-Pjax', 'Content');
@ -2220,7 +2220,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
['title' => $newPage->Title] ['title' => $newPage->Title]
) ?? '') ) ?? '')
); );
$url = $newPage->CMSEditLink(); $url = $newPage->getCMSEditLink();
$this->getResponse()->addHeader('X-ControllerURL', $url); $this->getResponse()->addHeader('X-ControllerURL', $url);
$this->getRequest()->addHeader('X-Pjax', 'Content'); $this->getRequest()->addHeader('X-Pjax', 'Content');
$this->getResponse()->addHeader('X-Pjax', 'Content'); $this->getResponse()->addHeader('X-Pjax', 'Content');
@ -2256,7 +2256,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
['title' => $newPage->Title] ['title' => $newPage->Title]
) ?? '') ) ?? '')
); );
$url = $newPage->CMSEditLink(); $url = $newPage->getCMSEditLink();
$this->getResponse()->addHeader('X-ControllerURL', $url); $this->getResponse()->addHeader('X-ControllerURL', $url);
$this->getRequest()->addHeader('X-Pjax', 'Content'); $this->getRequest()->addHeader('X-Pjax', 'Content');
$this->getResponse()->addHeader('X-Pjax', 'Content'); $this->getResponse()->addHeader('X-Pjax', 'Content');

View File

@ -16,7 +16,7 @@ class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem
{ {
return sprintf( return sprintf(
'<a href="%s">%s</a>', '<a href="%s">%s</a>',
$this->record->CMSEditLink(), $this->record->getCMSEditLink(),
_t('SilverStripe\\CMS\\Controllers\\ContentController.CMS', 'CMS') _t('SilverStripe\\CMS\\Controllers\\ContentController.CMS', 'CMS')
); );
} }
@ -28,7 +28,7 @@ class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem
public function getLink() public function getLink()
{ {
return $this->record->CMSEditLink(); return $this->record->getCMSEditLink();
} }
public function isActive() public function isActive()

View File

@ -285,7 +285,6 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
'Link' => 'Text', 'Link' => 'Text',
'RelativeLink' => 'Text', 'RelativeLink' => 'Text',
'AbsoluteLink' => 'Text', 'AbsoluteLink' => 'Text',
'CMSEditLink' => 'Text',
'TreeTitle' => 'HTMLFragment', 'TreeTitle' => 'HTMLFragment',
'MetaTags' => 'HTMLFragment', 'MetaTags' => 'HTMLFragment',
]; ];
@ -758,20 +757,6 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
return $link; 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. * Return a CSS identifier generated from this page's link.
* *
@ -1504,7 +1489,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$tags['cmsEditLink'] = [ $tags['cmsEditLink'] = [
'attributes' => [ 'attributes' => [
'name' => 'x-cms-edit-link', 'name' => 'x-cms-edit-link',
'content' => $this->CMSEditLink(), 'content' => $this->getCMSEditLink(),
], ],
]; ];
} }
@ -2157,11 +2142,11 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
'Untitled {instanceType}', 'Untitled {instanceType}',
['instanceType' => $item->i18n_singular_name()] ['instanceType' => $item->i18n_singular_name()]
); );
$tag = $item->hasMethod('CMSEditLink') ? 'a' : 'span'; $tag = $item->hasMethod('getCMSEditLink') ? 'a' : 'span';
return sprintf( return sprintf(
'<%s%s class="dependent-content__edit-link %s">%s</%s>', '<%s%s class="dependent-content__edit-link %s">%s</%s>',
$tag, $tag,
$tag === 'a' ? sprintf(' href="%s"', $item->CMSEditLink()) : '', $tag === 'a' ? sprintf(' href="%s"', $item->getCMSEditLink()) : '',
$title ? '' : 'dependent-content__edit-link--untitled', $title ? '' : 'dependent-content__edit-link--untitled',
$title ? Convert::raw2xml($title) : $untitled, $title ? Convert::raw2xml($title) : $untitled,
$tag $tag

View File

@ -258,7 +258,7 @@ class VirtualPage extends Page
'a', 'a',
[ [
'class' => 'cmsEditlink', 'class' => 'cmsEditlink',
'href' => $this->CopyContentFrom()->CMSEditLink(), 'href' => $this->CopyContentFrom()->getCMSEditLink(),
], ],
_t(VirtualPage::class . '.EditLink', 'edit') _t(VirtualPage::class . '.EditLink', 'edit')
); );

View File

@ -1505,7 +1505,7 @@ class SiteTreeTest extends SapphireTest
$this->assertStringContainsString('<meta name="description" content="The &lt;br /&gt; and &lt;br&gt; tags"', $meta); $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('<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-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); $this->assertStringContainsString('<title>HTML &amp; XML</title>', $meta);
// Test without title // Test without title
@ -1566,7 +1566,7 @@ class SiteTreeTest extends SapphireTest
'cmsEditLink' => [ 'cmsEditLink' => [
'attributes' => [ 'attributes' => [
'name' => 'x-cms-edit-link', 'name' => 'x-cms-edit-link',
'content' => $page->CMSEditLink() 'content' => $page->getCMSEditLink()
] ]
] ]
]; ];
@ -2084,11 +2084,11 @@ class SiteTreeTest extends SapphireTest
$child = $this->objFromFixture(BelongsToPage::class, 'one'); $child = $this->objFromFixture(BelongsToPage::class, 'one');
$this->assertSame( $this->assertSame(
"http://localhost/admin/pages/edit/show/$page->ID", "http://localhost/admin/pages/edit/show/$page->ID",
$page->CMSEditLink() $page->getCMSEditLink()
); );
$this->assertSame( $this->assertSame(
"http://localhost/admin/pages/edit/show/$page->ID/field/ChildObjects/item/$child->ID", "http://localhost/admin/pages/edit/show/$page->ID/field/ChildObjects/item/$child->ID",
$child->CMSEditLink() $child->getCMSEditLink()
); );
} }

View File

@ -105,7 +105,7 @@ class VirtualPageTest extends FunctionalTest
$this->assertStringContainsString('<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'"', $meta); $this->assertStringContainsString('<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'"', $meta);
$this->assertStringContainsString('<link rel="canonical" href="'.$master->AbsoluteLink().'"', $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-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); $this->assertStringContainsString('<title>'.$master->Title.'</title>', $meta);
} }