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

ENH Stop using Controller::has_curr() #1370

Merged
Merged
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
5 changes: 3 additions & 2 deletions code/Model/EditableCustomRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ protected function getCanCreateContext($args)
return $args[1]['Parent'];
}
// Hack in currently edited page if context is missing
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
return Controller::curr()->currentRecord();
$controller = Controller::curr();
if ($controller instanceof CMSMain) {
return $controller->currentRecord();
}

// No page being edited
Expand Down
9 changes: 5 additions & 4 deletions code/Model/EditableFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,13 @@ public function canEdit($member = null)
$parent = $this->Parent();
if ($parent && $parent->exists()) {
return $parent->canEdit($member) && !$this->isReadonly();
} elseif (!$this->exists() && Controller::has_curr()) {
} elseif (!$this->exists() && Controller::curr()) {
// This is for GridFieldOrderableRows support as it checks edit permissions on
// singleton of the class. Allows editing of User Defined Form pages by
// 'Content Authors' and those with permission to edit the UDF page. (ie. CanEditType/EditorGroups)
// This is to restore User Forms 2.x backwards compatibility.
$controller = Controller::curr();
if ($controller && $controller instanceof CMSPageEditController) {
if ($controller instanceof CMSPageEditController) {
$parent = $controller->getRecord($controller->currentRecordID());
// Only allow this behaviour on pages using UserFormFieldEditorExtension, such
// as UserDefinedForm page type.
Expand Down Expand Up @@ -572,8 +572,9 @@ protected function getCanCreateContext($args)
return $args[1]['Parent'];
}
// Hack in currently edited page if context is missing
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
return Controller::curr()->currentRecord();
$controller = Controller::curr();
if ($controller instanceof CMSMain) {
return $controller->currentRecord();
}

// No page being edited
Expand Down
5 changes: 3 additions & 2 deletions code/Model/Recipient/EmailRecipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,9 @@ protected function getCanCreateContext($args)
return $args[1][Form::class];
}
// Hack in currently edited page if context is missing
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
return Controller::curr()->currentRecord();
$controller = Controller::curr();
if ($controller instanceof CMSMain) {
return $controller->currentRecord();
}

// No page being edited
Expand Down
5 changes: 3 additions & 2 deletions code/Model/Recipient/EmailRecipientCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ protected function getCanCreateContext($args)
return $args[1]['Parent'];
}
// Hack in currently edited page if context is missing
if (Controller::has_curr() && Controller::curr() instanceof CMSMain) {
return Controller::curr()->currentRecord();
$controller = Controller::curr();
if ($controller instanceof CMSMain) {
return $controller->currentRecord();
}

// No page being edited
Expand Down
Loading