Skip to content

Commit

Permalink
API Deprecate API which will be removed in CMS 6
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Dec 8, 2024
1 parent ee22a35 commit 40b4345
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 21 deletions.
1 change: 1 addition & 0 deletions code/CMSEditLinkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function getCMSEditLinkForManagedDataObject(DataObject $obj, string $reci

/**
* Get a link to edit this DataObject in the CMS.
* @deprecated 2.4.0 Will be replaced with SilverStripe\ORM\DataObject::getCMSEditLink() and updateCMSEditLink()
*/
public function CMSEditLink(): string
{
Expand Down
2 changes: 1 addition & 1 deletion code/CMSMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public static function get_viewable_menu_items($member = null)
$controllerObj = singleton($menuItem->controller);
if (Controller::has_curr()) {
// Necessary for canView() to have request data available,
// e.g. to check permissions against LeftAndMain->currentPage()
// e.g. to check permissions against LeftAndMain->currentRecord()
$controllerObj->setRequest(Controller::curr()->getRequest());
if (!$controllerObj->canView($member)) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion code/CMSProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CMSProfileController extends LeftAndMain

public function getEditForm($id = null, $fields = null)
{
$this->setCurrentPageID(Security::getCurrentUser()->ID);
$this->setCurrentRecordID(Security::getCurrentUser()->ID);

$form = parent::getEditForm($id, $fields);

Expand Down
88 changes: 69 additions & 19 deletions code/LeftAndMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,15 @@ class LeftAndMain extends Controller implements PermissionProvider
* Current pageID for this request
*
* @var null
* @deprecated 2.4.0 use recordID instead.
*/
protected $pageID = null;

/**
* ID of the current record for this request
*/
protected ?int $recordID = null;

/**
* Set by {@link LeftAndMainErrorExtension} if an http error occurs
*/
Expand Down Expand Up @@ -1029,7 +1035,7 @@ public static function menu_icon_class_for_class($class)
public function show(HTTPRequest $request): HTTPResponse
{
if ($request->param('ID')) {
$this->setCurrentPageID($request->param('ID'));
$this->setCurrentRecordID($request->param('ID'));
}
return $this->getResponseNegotiator()->respond($request);
}
Expand Down Expand Up @@ -1322,7 +1328,7 @@ public function save(array $data, Form $form): HTTPResponse
$form->saveInto($record, true);
$record->write();
$this->extend('onAfterSave', $record);
$this->setCurrentPageID($record->ID);
$this->setCurrentRecordID($record->ID);

$message = _t(__CLASS__ . '.SAVEDUP', 'Saved.');
if ($this->getSchemaRequested()) {
Expand Down Expand Up @@ -1413,7 +1419,7 @@ public function EditForm($request = null)
public function getEditForm($id = null, $fields = null)
{
if (!$id) {
$id = $this->currentPageID();
$id = $this->currentRecordID();
}

// Check record exists
Expand Down Expand Up @@ -1669,7 +1675,7 @@ public function BatchActionsForm()

public function printable()
{
$form = $this->getEditForm($this->currentPageID());
$form = $this->getEditForm($this->currentRecordID());
if (!$form) {
return false;
}
Expand All @@ -1692,7 +1698,7 @@ public function printable()
public function getSilverStripeNavigator(?DataObject $record = null)
{
if (!$record) {
$record = $this->currentPage();
$record = $this->currentRecord();
}
if ($record && (($record instanceof CMSPreviewable) || $record->has_extension(CMSPreviewable::class))) {
$navigator = new SilverStripeNavigator($record);
Expand All @@ -1710,30 +1716,42 @@ public function getSilverStripeNavigator(?DataObject $record = null)
* - Session value namespaced by classname, e.g. "CMSMain.currentPage"
*
* @return int
* @deprecated 5.4.0 use currentRecordID() instead.
*/
public function currentPageID()
{
if ($this->pageID) {
return $this->pageID;
}
Deprecation::notice('5.4.0', 'use currentRecordID() instead.');
return $this->currentRecordID();
}

/**
* Identifier for the currently shown record,
* in most cases a database ID. Inspects the following
* sources (in this order):
* - GET/POST parameter named 'ID'
* - URL parameter named 'ID'
* - Session value namespaced by classname, e.g. "CMSMain.currentPage"
*/
public function currentRecordID(): ?int
{
if ($this->getRequest()->requestVar('ID') && is_numeric($this->getRequest()->requestVar('ID'))) {
return $this->getRequest()->requestVar('ID');
return (int) $this->getRequest()->requestVar('ID');
}

if ($this->getRequest()->requestVar('CMSMainCurrentPageID') && is_numeric($this->getRequest()->requestVar('CMSMainCurrentPageID'))) {
// see GridFieldDetailForm::ItemEditForm
return $this->getRequest()->requestVar('CMSMainCurrentPageID');
return (int) $this->getRequest()->requestVar('CMSMainCurrentPageID');
}

if (isset($this->urlParams['ID']) && is_numeric($this->urlParams['ID'])) {
return $this->urlParams['ID'];
return (int) $this->urlParams['ID'];
}

if (is_numeric($this->getRequest()->param('ID'))) {
return $this->getRequest()->param('ID');
return (int) $this->getRequest()->param('ID');
}

/** @deprecated */
// Using session for this is deprecated - see https://github.com/silverstripe/silverstripe-admin/pull/19
$session = $this->getRequest()->getSession();
return $session->get($this->sessionNamespace() . ".currentPage") ?: null;
}
Expand All @@ -1745,12 +1763,23 @@ public function currentPageID()
* as a URL parameter will overrule this value.
*
* @param int $id
* @deprecated 5.4.0 use setCurrentRecordID() instead.
*/
public function setCurrentPageID($id)
{
$this->pageID = $id;
Deprecation::notice('5.4.0', 'use setCurrentRecordID() instead.');
$id = (int)$id;
/** @deprecated */
$this->setCurrentRecordID($id);
}

/**
* Sets the ID for the current record which can be retrieved later through {@link currentRecordID()}.
* Keep in mind that setting an ID through GET/POST or as a URL parameter will overrule this value.
*/
public function setCurrentRecordID(int $id): void
{
$this->recordID = $id;
// Setting session for this is deprecated - see https://github.com/silverstripe/silverstripe-admin/pull/19
$this->getRequest()->getSession()->set($this->sessionNamespace() . ".currentPage", $id);
}

Expand All @@ -1759,22 +1788,43 @@ public function setCurrentPageID($id)
* to get the currently selected record.
*
* @return DataObject
* @deprecated 5.4.0 use currentRecord() instead.
*/
public function currentPage()
{
return $this->getRecord($this->currentPageID());
Deprecation::notice('5.4.0', 'use currentRecord() instead.');
return $this->currentRecord();
}

/**
* Uses {@link getRecord()} and {@link currentRecordID()}
* to get the currently selected record.
*/
public function currentRecord(): DataObject
{
return $this->getRecord($this->currentRecordID());
}

/**
* Compares a given record to the currently selected one (if any).
* Used for marking the current tree node.
*
* @param DataObject $record
* @return bool
* @deprecated 5.4.0 use isCurrentRecord() instead.
*/
public function isCurrentPage(DataObject $record)
{
return ($record->ID == $this->currentPageID());
Deprecation::notice('5.4.0', 'use isCurrentRecord() instead.');
return $this->isCurrentRecord($record);
}

/**
* Compares a given record to the currently selected one (if any).
* Used for marking the current tree node.
*/
public function isCurrentRecord(DataObject $record): bool
{
return ($record->ID == $this->currentRecordID());
}

/**
Expand Down Expand Up @@ -1833,7 +1883,7 @@ public function CMSVersionNumber()
*/
public function SwitchView()
{
$page = $this->currentPage();
$page = $this->currentRecord();
if (!$page) {
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions code/LeftAndMain_SearchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function getNumChildrenMethod();
*
* @param DataObject $page
* @return bool
* @deprecated 5.4.0 will be renamed to isRecordIncluded().
*/
public function isPageIncluded($page);

Expand All @@ -40,6 +41,7 @@ public function isPageIncluded($page);
*
* @param DataObject $page
* @return array|string
* @deprecated 5.4.0 will be renamed to getRecordClasses().
*/
public function getPageClasses($page);
}

0 comments on commit 40b4345

Please sign in to comment.