Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Stop refering to "pages" when dealing with generic records #1837

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/src/styles/legacy/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ html, body {
margin-right: 10px;
}

.page-icon {
.record-icon {
display: inline-block;
margin-right: 6px;

Expand Down
14 changes: 7 additions & 7 deletions client/src/styles/legacy/_tree.scss
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
color: #FFF;
border: 0;
// Specificity override for icons in children pages
.jstree-pageicon {
.jstree-recordicon {
color: #FFF;
}
}
Expand All @@ -324,7 +324,7 @@
text-decoration: none;
margin-right: 2px;
}
.jstree-pageicon {
.jstree-recordicon {
margin-top: 3px;
margin-right: 5px;
}
Expand Down Expand Up @@ -668,7 +668,7 @@

/* Page icons */

.page-icon, a .jstree-pageicon {
.record-icon, a .jstree-recordicon {
display: block;
width: 16px;
height: 16px;
Expand All @@ -679,7 +679,7 @@
}
}

a .jstree-pageicon {
a .jstree-recordicon {
float: left;
margin-right: 4px;
position: relative;
Expand All @@ -692,7 +692,7 @@ a .jstree-pageicon {
}

@mixin tree-status-icon($label, $dotColor, $textColor, $bgColor) {
.cms-tree.jstree .status-#{$label} > a .jstree-pageicon:after {
.cms-tree.jstree .status-#{$label} > a .jstree-recordicon:after {
content:"";
display: block;
width: 8px;
Expand All @@ -711,7 +711,7 @@ a .jstree-pageicon {
border-color:$textColor;
}
// Dots
.cms-tree.jstree .status-#{$label} > a .jstree-pageicon:after {
.cms-tree.jstree .status-#{$label} > a .jstree-recordicon:after {
background-color:$dotColor;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3), inset 0 0 0 1px $textColor;
}
Expand Down Expand Up @@ -760,7 +760,7 @@ a .jstree-pageicon {
.jstree-icon {
background-image: none !important;
}
.jstree-pageicon {
.jstree-recordicon {
background: url('../../images/throbber.gif') top left no-repeat;
}
}
Expand Down
8 changes: 7 additions & 1 deletion code/CMSBatchAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Admin;

use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPResponse;
Expand Down Expand Up @@ -107,9 +108,14 @@ public function batchaction(SS_List $objs, $helperMethod, $successMessage, $argu

// Now make sure the tree title is appropriately updated
$publishedRecord = DataObject::get_by_id($this->managedClass, $id);
if ($publishedRecord instanceof SiteTree) {
$treeTitle = CMSMain::singleton()->getRecordTreeMarkup($publishedRecord);
} else {
$treeTitle = $publishedRecord->TreeTitle;
}
if ($publishedRecord) {
$status['modified'][$id] = [
'TreeTitle' => $publishedRecord->TreeTitle,
'TreeTitle' => $treeTitle,
];
} else {
$status['deleted'][$id] = $id;
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -379,7 +379,7 @@ public static function get_cms_classes($root = null, $recursive = true, $sort =
if (!$root) {
$root = LeftAndMain::class;
}
$abstractClasses = [LeftAndMain::class, CMSMain::class];
$abstractClasses = [LeftAndMain::class];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is needed so that CMSMain can be included in the left menu and have its route built.
Without this, it was the CMSPagesController which was a very-nearly-useless subclass of CMSMain that was used.
That class has been merged into CMSMain so we need its menu item back

$subClasses = array_values(ClassInfo::subclassesFor($root) ?? []);
foreach ($subClasses as $className) {
if ($recursive && $className != $root) {
Expand Down
2 changes: 1 addition & 1 deletion code/CMSProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function init()
{
parent::init();
if (!$this->getResponse()->isRedirect()) {
$this->setCurrentPageID(Security::getCurrentUser()->ID);
$this->setCurrentRecordID(Security::getCurrentUser()->ID);
}
}

Expand Down
79 changes: 42 additions & 37 deletions code/LeftAndMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@ class LeftAndMain extends FormSchemaController implements PermissionProvider
*
* Determines what is managed in this interface, through
* {@link getEditForm()} and other logic.
*
* @config
* @var string
*/
private static $model_class = null;
private static ?string $model_class = null;

/**
* @var array
Expand Down Expand Up @@ -583,7 +580,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 @@ -769,15 +766,23 @@ public function PreviewPanel()
return null;
}

/**
* Get the class of the model which is managed by this controller.
* @return class-string<DataObject>
*/
public function getModelClass(): string
{
return static::config()->get('model_class') ?? '';
}

/**
* Get dataobject from the current ID
*
* @param int|DataObject $id ID or object
* @return DataObject
*/
public function getRecord($id)
public function getRecord($id): ?DataObject
{
$className = $this->config()->get('model_class');
$className = $this->getModelClass();
if (!$className) {
return null;
}
Expand Down Expand Up @@ -843,7 +848,7 @@ protected function getSearchFilter()
public function save(array $data, Form $form): HTTPResponse
{
$request = $this->getRequest();
$className = $this->config()->get('model_class');
$className = $this->getModelClass();

// Existing or new record?
$id = $data['ID'];
Expand All @@ -856,7 +861,7 @@ public function save(array $data, Form $form): HTTPResponse
$this->httpError(404, "Bad record ID #" . (int)$id);
}
} else {
if (!singleton($this->config()->get('model_class'))->canCreate()) {
if (!DataObject::singleton($className)->canCreate()) {
return Security::permissionFailure($this);
}
$record = $this->getNewItem($id, false);
Expand All @@ -866,7 +871,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 All @@ -892,7 +897,7 @@ public function save(array $data, Form $form): HTTPResponse
*/
public function getNewItem($id, $setID = true)
{
$class = $this->config()->get('model_class');
$class = $this->getModelClass();
$object = Injector::inst()->create($class);
if ($setID) {
$object->ID = $id;
Expand All @@ -902,7 +907,7 @@ public function getNewItem($id, $setID = true)

public function delete(array $data, Form $form): HTTPResponse
{
$className = $this->config()->get('model_class');
$className = $this->getModelClass();

$id = $data['ID'];
$record = DataObject::get_by_id($className, $id);
Expand Down Expand Up @@ -932,9 +937,9 @@ public function delete(array $data, Form $form): HTTPResponse
*
* This is a "pseudo-abstract" method, usually connected to a {@link getEditForm()}
* method in an entwine subclass. This method can accept a record identifier,
* selected either in custom logic, or through {@link currentPageID()}.
* selected either in custom logic, or through {@link currentRecordID()}.
* The form usually construct itself from {@link DataObject->getCMSFields()}
* for the specific managed subclass defined in {@link LeftAndMain::$model_class}.
* for the specific managed subclass defined in {@link LeftAndMain::getModelClass()}.
*
* @param HTTPRequest $request Passed if executing a HTTPRequest directly on the form.
* If empty, this is invoked as $EditForm in the template
Expand All @@ -957,7 +962,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 @@ -987,7 +992,7 @@ public function getEditForm($id = null, $fields = null)
$fields->push(new HiddenField('ClassName'));
}

$modelClass = $this->config()->get('model_class');
$modelClass = $this->getModelClass();
if ($modelClass::has_extension(Hierarchy::class)
&& !$fields->dataFieldByName('ParentID')
) {
Expand Down Expand Up @@ -1141,7 +1146,7 @@ public function EditFormTools()
*/
public function batchactions()
{
return new CMSBatchActionHandler($this, 'batchactions', $this->config()->get('model_class'));
return new CMSBatchActionHandler($this, 'batchactions', $this->getModelClass());
}

/**
Expand Down Expand Up @@ -1186,7 +1191,7 @@ public function BatchActionsForm()

public function printable()
{
$form = $this->getEditForm($this->currentPageID());
$form = $this->getEditForm($this->currentRecordID());
if (!$form) {
return false;
}
Expand All @@ -1209,7 +1214,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 @@ -1224,11 +1229,11 @@ public function getSilverStripeNavigator(?DataObject $record = null)
* sources (in this order):
* - GET/POST parameter named 'ID'
* - URL parameter named 'ID'
* - Session value namespaced by classname, e.g. "CMSMain.currentPage"
* - Session value namespaced by classname, e.g. "CMSMain.currentRecord"
*
* @return int
*/
public function currentPageID()
public function currentRecordID()
{
if ($this->pageID) {
return $this->pageID;
Expand All @@ -1237,9 +1242,9 @@ public function currentPageID()
return $this->getRequest()->requestVar('ID');
}

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

if (isset($this->urlParams['ID']) && is_numeric($this->urlParams['ID'])) {
Expand All @@ -1252,34 +1257,34 @@ public function currentPageID()

/** @deprecated */
$session = $this->getRequest()->getSession();
return $session->get($this->sessionNamespace() . ".currentPage") ?: null;
return $session->get($this->sessionNamespace() . ".currentRecord") ?: null;
}

/**
* Forces the current page to be set in session,
* which can be retrieved later through {@link currentPageID()}.
* 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.
*
* @param int $id
*/
public function setCurrentPageID($id)
public function setCurrentRecordID($id)
{
$this->pageID = $id;
$id = (int)$id;
/** @deprecated */
$this->getRequest()->getSession()->set($this->sessionNamespace() . ".currentPage", $id);
$this->getRequest()->getSession()->set($this->sessionNamespace() . ".currentRecord", $id);
}

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

/**
Expand All @@ -1289,9 +1294,9 @@ public function currentPage()
* @param DataObject $record
* @return bool
*/
public function isCurrentPage(DataObject $record)
public function isCurrentRecord(DataObject $record)
{
return ($record->ID == $this->currentPageID());
return ($record->ID == $this->currentRecordID());
}

/**
Expand Down Expand Up @@ -1350,7 +1355,7 @@ public function CMSVersionNumber()
*/
public function SwitchView()
{
$page = $this->currentPage();
$page = $this->currentRecord();
if (!$page) {
return null;
}
Expand Down Expand Up @@ -1477,7 +1482,7 @@ public function providePermissions()
$perms = [
"CMS_ACCESS_LeftAndMain" => [
'name' => _t(__CLASS__ . '.ACCESSALLINTERFACES', 'Access to all CMS sections'),
'category' => _t(Permission::class . '.CMS_ACCESS_CATEGORY', 'CMS Access'),
'category' => _t(__CLASS__ . '.CMS_ACCESS_CATEGORY', 'CMS Access'),
'help' => _t(__CLASS__ . '.ACCESSALLINTERFACESHELP', 'Overrules more specific access settings.'),
'sort' => -100
]
Expand Down Expand Up @@ -1509,11 +1514,11 @@ public function providePermissions()
$perms[$code] = [
// Item in permission selection identifying the admin section. Example: Access to 'Files & Images'
'name' => _t(
CMSMain::class . '.ACCESS',
__CLASS__ . '.ACCESS',
"Access to '{title}' section",
['title' => $title]
),
'category' => _t(Permission::class . '.CMS_ACCESS_CATEGORY', 'CMS Access')
'category' => _t(__CLASS__ . '.CMS_ACCESS_CATEGORY', 'CMS Access')
];
}

Expand Down
Loading
Loading