ENH Use class name instead of self

This commit is contained in:
Steve Boyd 2024-06-14 21:49:48 +12:00
parent b429efb2ba
commit 6541365a8e
5 changed files with 16 additions and 16 deletions

View File

@ -297,7 +297,7 @@ class UserDefinedFormAdmin extends LeftAndMain
private static function updateFormSubmissionFolderPermissions() private static function updateFormSubmissionFolderPermissions()
{ {
// ensure the FormSubmissions folder is only accessible to Administrators // ensure the FormSubmissions folder is only accessible to Administrators
$formSubmissionsFolder = Folder::find(self::config()->get('form_submissions_folder')); $formSubmissionsFolder = Folder::find(static::config()->get('form_submissions_folder'));
$formSubmissionsFolder->CanViewType = InheritedPermissions::ONLY_THESE_USERS; $formSubmissionsFolder->CanViewType = InheritedPermissions::ONLY_THESE_USERS;
$formSubmissionsFolder->ViewerGroups()->removeAll(); $formSubmissionsFolder->ViewerGroups()->removeAll();
$formSubmissionsFolder->ViewerGroups()->add(Group::get_one(Group::class, ['"Code"' => 'administrators'])); $formSubmissionsFolder->ViewerGroups()->add(Group::get_one(Group::class, ['"Code"' => 'administrators']));
@ -314,16 +314,16 @@ class UserDefinedFormAdmin extends LeftAndMain
*/ */
public static function getFormSubmissionFolder(string $subFolder = null): ?Folder public static function getFormSubmissionFolder(string $subFolder = null): ?Folder
{ {
$folderPath = self::config()->get('form_submissions_folder'); $folderPath = static::config()->get('form_submissions_folder');
if ($subFolder) { if ($subFolder) {
$folderPath .= '/' . $subFolder; $folderPath .= '/' . $subFolder;
} }
$formSubmissionsFolderExists = !!Folder::find(self::config()->get('form_submissions_folder')); $formSubmissionsFolderExists = !!Folder::find(static::config()->get('form_submissions_folder'));
$folder = Folder::find_or_make($folderPath); $folder = Folder::find_or_make($folderPath);
// Set default permissions if this is the first time we create the form submission folder // Set default permissions if this is the first time we create the form submission folder
if (!$formSubmissionsFolderExists) { if (!$formSubmissionsFolderExists) {
self::updateFormSubmissionFolderPermissions(); UserDefinedFormAdmin::updateFormSubmissionFolderPermissions();
// Make sure we return the folder with the latest permission // Make sure we return the folder with the latest permission
$folder = Folder::find($folderPath); $folder = Folder::find($folderPath);
} }

View File

@ -59,7 +59,7 @@ class UserDefinedFormController extends PageController
/** /**
* Size that an uploaded file must not excede for it to be attached to an email * Size that an uploaded file must not excede for it to be attached to an email
* Follows PHP "shorthand bytes" definition rules. * Follows PHP "shorthand bytes" definition rules.
* @see self::parseByteSizeString() * @see UserDefinedFormController::parseByteSizeString()
* *
* @var int * @var int
* @config * @config
@ -314,7 +314,7 @@ JS
} }
$file = Versioned::withVersionedMode(function () use ($field, $form) { $file = Versioned::withVersionedMode(function () use ($field, $form) {
$stage = Injector::inst()->get(self::class)->config()->get('file_upload_stage'); $stage = Injector::inst()->get(UserDefinedFormController::class)->config()->get('file_upload_stage');
Versioned::set_stage($stage); Versioned::set_stage($stage);
$foldername = $field->getFormField()->getFolderName(); $foldername = $field->getFormField()->getFolderName();

View File

@ -47,8 +47,8 @@ class UserFormFileExtension extends DataExtension
public function updateTrackedFormUpload(&$value): void public function updateTrackedFormUpload(&$value): void
{ {
$file = $this->owner; $file = $this->owner;
if ($file->UserFormUpload != self::USER_FORM_UPLOAD_UNKNOWN) { if ($file->UserFormUpload != UserFormFileExtension::USER_FORM_UPLOAD_UNKNOWN) {
$value = $file->UserFormUpload == self::USER_FORM_UPLOAD_TRUE; $value = $file->UserFormUpload == UserFormFileExtension::USER_FORM_UPLOAD_TRUE;
return; return;
} }
if ($file->ClassName == Folder::class) { if ($file->ClassName == Folder::class) {
@ -71,7 +71,7 @@ class UserFormFileExtension extends DataExtension
} }
$tableName = Convert::raw2sql(DataObject::getSchema()->tableName(File::class)); $tableName = Convert::raw2sql(DataObject::getSchema()->tableName(File::class));
$column = 'UserFormUpload'; $column = 'UserFormUpload';
$enumVal = $value ? self::USER_FORM_UPLOAD_TRUE : self::USER_FORM_UPLOAD_FALSE; $enumVal = $value ? UserFormFileExtension::USER_FORM_UPLOAD_TRUE : UserFormFileExtension::USER_FORM_UPLOAD_FALSE;
SQLUpdate::create() SQLUpdate::create()
->setTable(sprintf('"%s"', $tableName)) ->setTable(sprintf('"%s"', $tableName))
->addWhere(['"ID" = ?' => [$this->owner->ID]]) ->addWhere(['"ID" = ?' => [$this->owner->ID]])

View File

@ -281,9 +281,9 @@ class EditableFormField extends DataObject
$fields->fieldByName('Root.Main')->setTitle(_t('SilverStripe\\CMS\\Model\\SiteTree.TABMAIN', 'Main')); $fields->fieldByName('Root.Main')->setTitle(_t('SilverStripe\\CMS\\Model\\SiteTree.TABMAIN', 'Main'));
// Custom settings // Custom settings
if (!empty(self::$allowed_css)) { if (!empty(EditableFormField::$allowed_css)) {
$cssList = []; $cssList = [];
foreach (self::$allowed_css as $k => $v) { foreach (EditableFormField::$allowed_css as $k => $v) {
if (!is_array($v)) { if (!is_array($v)) {
$cssList[$k]=$v; $cssList[$k]=$v;
} elseif ($k === $this->ClassName) { } elseif ($k === $this->ClassName) {
@ -351,7 +351,7 @@ class EditableFormField extends DataObject
// make sure to migrate the class across (prior to v5.x) // make sure to migrate the class across (prior to v5.x)
DB::query("UPDATE \"EditableFormField\" SET \"ParentClass\" = 'Page' WHERE \"ParentClass\" IS NULL"); DB::query("UPDATE \"EditableFormField\" SET \"ParentClass\" = 'Page' WHERE \"ParentClass\" IS NULL");
if (self::has_extension(Versioned::class)) { if (EditableFormField::has_extension(Versioned::class)) {
DB::query("UPDATE \"EditableFormField_Live\" SET \"ParentClass\" = 'Page' WHERE \"ParentClass\" IS NULL"); DB::query("UPDATE \"EditableFormField_Live\" SET \"ParentClass\" = 'Page' WHERE \"ParentClass\" IS NULL");
DB::query("UPDATE \"EditableFormField_Versions\" SET \"ParentClass\" = 'Page' WHERE \"ParentClass\" IS NULL"); DB::query("UPDATE \"EditableFormField_Versions\" SET \"ParentClass\" = 'Page' WHERE \"ParentClass\" IS NULL");
} }
@ -602,7 +602,7 @@ class EditableFormField extends DataObject
{ {
if (is_array($allowed)) { if (is_array($allowed)) {
foreach ($allowed as $k => $v) { foreach ($allowed as $k => $v) {
self::$allowed_css[$k] = (!is_null($v)) ? $v : $k; EditableFormField::$allowed_css[$k] = (!is_null($v)) ? $v : $k;
} }
} }
} }

View File

@ -55,7 +55,7 @@ class EditableOption extends DataObject
*/ */
public static function allow_empty_values() public static function allow_empty_values()
{ {
return (bool) self::$allow_empty_values; return (bool) EditableOption::$allow_empty_values;
} }
/** /**
@ -65,7 +65,7 @@ class EditableOption extends DataObject
*/ */
public static function set_allow_empty_values($allow) public static function set_allow_empty_values($allow)
{ {
self::$allow_empty_values = (bool) $allow; EditableOption::$allow_empty_values = (bool) $allow;
} }
/** /**
@ -77,7 +77,7 @@ class EditableOption extends DataObject
public function getValue() public function getValue()
{ {
$value = $this->getField('Value'); $value = $this->getField('Value');
if (empty($value) && !self::allow_empty_values()) { if (empty($value) && !EditableOption::allow_empty_values()) {
return $this->Title; return $this->Title;
} }
return $value; return $value;