ENH Use class name instead of self

This commit is contained in:
Steve Boyd 2024-06-05 16:30:08 +12:00
parent 4e241f5ebc
commit 09db0d33d2
6 changed files with 29 additions and 29 deletions

View File

@ -365,7 +365,7 @@ class Company extends DataObject
public function scaffoldSearchField() public function scaffoldSearchField()
{ {
return DropdownField::create('CompanyID', 'Company', self::get()->map())->setEmptyString(''); return DropdownField::create('CompanyID', 'Company', Company::get()->map())->setEmptyString('');
} }
} }

View File

@ -56,10 +56,10 @@ class ArbitraryDataAdmin extends LeftAndMain
// accessing the admin directly // accessing the admin directly
if ($this->tab === null) { if ($this->tab === null) {
$this->tab = self::TAB_ARRAYDATA; $this->tab = ArbitraryDataAdmin::TAB_ARRAYDATA;
} }
if ($this->tab !== self::TAB_ARRAYDATA && $this->tab !== self::TAB_CUSTOM_MODEL) { if ($this->tab !== ArbitraryDataAdmin::TAB_ARRAYDATA && $this->tab !== ArbitraryDataAdmin::TAB_CUSTOM_MODEL) {
throw new RuntimeException("Unexpected url segment: {$this->tab}"); throw new RuntimeException("Unexpected url segment: {$this->tab}");
} }
} }
@ -69,12 +69,12 @@ class ArbitraryDataAdmin extends LeftAndMain
$list = ArrayList::create(); $list = ArrayList::create();
switch ($this->tab) { switch ($this->tab) {
case self::TAB_ARRAYDATA: case ArbitraryDataAdmin::TAB_ARRAYDATA:
foreach (self::getInitialRecords() as $stub) { foreach (ArbitraryDataAdmin::getInitialRecords() as $stub) {
$list->add(ArrayData::create($stub)); $list->add(ArrayData::create($stub));
} }
break; break;
case self::TAB_CUSTOM_MODEL: case ArbitraryDataAdmin::TAB_CUSTOM_MODEL:
$rawData = SQLSelect::create()->setFrom(ArbitraryDataModel::TABLE_NAME)->execute(); $rawData = SQLSelect::create()->setFrom(ArbitraryDataModel::TABLE_NAME)->execute();
foreach ($rawData as $record) { foreach ($rawData as $record) {
$list->add(ArbitraryDataModel::create($record)); $list->add(ArbitraryDataModel::create($record));
@ -105,14 +105,14 @@ class ArbitraryDataAdmin extends LeftAndMain
protected function getGridFieldConfig(): GridFieldConfig protected function getGridFieldConfig(): GridFieldConfig
{ {
if ($this->tab === self::TAB_CUSTOM_MODEL) { if ($this->tab === ArbitraryDataAdmin::TAB_CUSTOM_MODEL) {
$config = GridFieldConfig_RecordEditor::create(); $config = GridFieldConfig_RecordEditor::create();
} else { } else {
// This is effectively the same as a GridFieldConfig_RecordViewer, but without removing the GridFieldFilterHeader. // This is effectively the same as a GridFieldConfig_RecordViewer, but without removing the GridFieldFilterHeader.
$config = GridFieldConfig_Base::create(); $config = GridFieldConfig_Base::create();
$config->addComponent(GridFieldViewButton::create()); $config->addComponent(GridFieldViewButton::create());
$config->addComponent(GridFieldDetailForm::create()); $config->addComponent(GridFieldDetailForm::create());
$fieldNames = array_keys(self::getInitialRecords()[0]); $fieldNames = array_keys(ArbitraryDataAdmin::getInitialRecords()[0]);
$config->getComponentByType(GridFieldDataColumns::class)->setDisplayFields(array_combine($fieldNames, $fieldNames)); $config->getComponentByType(GridFieldDataColumns::class)->setDisplayFields(array_combine($fieldNames, $fieldNames));
$fields = array_map(fn ($name) => $name === 'ID' ? HiddenField::create($name) : TextField::create($name), $fieldNames); $fields = array_map(fn ($name) => $name === 'ID' ? HiddenField::create($name) : TextField::create($name), $fieldNames);
$config->getComponentByType(GridFieldDetailForm::class)->setFields(FieldList::create($fields)); $config->getComponentByType(GridFieldDetailForm::class)->setFields(FieldList::create($fields));
@ -188,8 +188,8 @@ class ArbitraryDataAdmin extends LeftAndMain
protected function getManagedTabs() protected function getManagedTabs()
{ {
$tabs = [ $tabs = [
self::TAB_ARRAYDATA => 'ArrayData', ArbitraryDataAdmin::TAB_ARRAYDATA => 'ArrayData',
self::TAB_CUSTOM_MODEL => 'Custom Model', ArbitraryDataAdmin::TAB_CUSTOM_MODEL => 'Custom Model',
]; ];
$forms = new ArrayList(); $forms = new ArrayList();

View File

@ -61,7 +61,7 @@ class ArbitraryDataModel extends ArrayData implements DataObjectInterface
} }
// Remove anything that isn't storable in the DB, such as Security ID // Remove anything that isn't storable in the DB, such as Security ID
$dbColumns = DB::field_list(self::TABLE_NAME); $dbColumns = DB::field_list(ArbitraryDataModel::TABLE_NAME);
foreach ($record as $fieldName => $value) { foreach ($record as $fieldName => $value) {
if (!array_key_exists($fieldName, $dbColumns)) { if (!array_key_exists($fieldName, $dbColumns)) {
unset($record[$fieldName]); unset($record[$fieldName]);
@ -76,11 +76,11 @@ class ArbitraryDataModel extends ArrayData implements DataObjectInterface
if (!$isNew) { if (!$isNew) {
$manipulation['id'] = $this->ID; $manipulation['id'] = $this->ID;
} }
DB::manipulate([self::TABLE_NAME => $manipulation]); DB::manipulate([ArbitraryDataModel::TABLE_NAME => $manipulation]);
if ($isNew) { if ($isNew) {
// Must save the ID in this object so GridField knows what URL to redirect to. // Must save the ID in this object so GridField knows what URL to redirect to.
$this->ID = DB::get_generated_id(self::TABLE_NAME); $this->ID = DB::get_generated_id(ArbitraryDataModel::TABLE_NAME);
} }
} }
@ -89,7 +89,7 @@ class ArbitraryDataModel extends ArrayData implements DataObjectInterface
if (!$this->ID) { if (!$this->ID) {
throw new LogicException('DataObject::delete() called on a record without an ID'); throw new LogicException('DataObject::delete() called on a record without an ID');
} }
SQLDelete::create()->setFrom(self::TABLE_NAME)->setWhere(['ID' => $this->ID])->execute(); SQLDelete::create()->setFrom(ArbitraryDataModel::TABLE_NAME)->setWhere(['ID' => $this->ID])->execute();
$this->ID = 0; $this->ID = 0;
} }

View File

@ -36,7 +36,7 @@ class TestPage extends Page implements \TestPageInterface
public function requireDefaultRecords() public function requireDefaultRecords()
{ {
if (static::class === self::class) { if (static::class === TestPage::class) {
return; return;
} }
@ -46,7 +46,7 @@ class TestPage extends Page implements \TestPageInterface
Member::actAs($defaultAdminService->findOrCreateDefaultAdmin(), function () { Member::actAs($defaultAdminService->findOrCreateDefaultAdmin(), function () {
// Create actual page // Create actual page
$page = new static(); $page = new static();
$page->Title = str_replace(self::class, "", static::class); $page->Title = str_replace(TestPage::class, "", static::class);
$page->ShowInMenus = 0; $page->ShowInMenus = 0;
$parent = static::getOrCreateParentPage(); $parent = static::getOrCreateParentPage();
$page->ParentID = $parent->ID; $page->ParentID = $parent->ID;

View File

@ -228,7 +228,7 @@ class FTFileMakerTask extends BuildTask
return (int) trim($int ?? ''); return (int) trim($int ?? '');
}, $counts ?? []); }, $counts ?? []);
} else { } else {
$this->fileCounts = self::config()->get('fileCountByDepth'); $this->fileCounts = FTFileMakerTask::config()->get('fileCountByDepth');
} }
$folderCounts = $request->getVar('folderCounts'); $folderCounts = $request->getVar('folderCounts');
@ -238,13 +238,13 @@ class FTFileMakerTask extends BuildTask
return (int) trim($int ?? ''); return (int) trim($int ?? '');
}, $counts ?? []); }, $counts ?? []);
} else { } else {
$this->folderCounts = self::config()->get('folderCountByDepth'); $this->folderCounts = FTFileMakerTask::config()->get('folderCountByDepth');
} }
echo "Downloading fixtures" . $this->lineBreak; echo "Downloading fixtures" . $this->lineBreak;
$fixtureFilePaths = $this->downloadFixtureFiles(); $fixtureFilePaths = $this->downloadFixtureFiles();
if (!self::config()->get('documentsOnly')) { if (!FTFileMakerTask::config()->get('documentsOnly')) {
echo "Generate thumbnails" . $this->lineBreak; echo "Generate thumbnails" . $this->lineBreak;
$this->generateThumbnails($fixtureFilePaths); $this->generateThumbnails($fixtureFilePaths);
} }
@ -252,7 +252,7 @@ class FTFileMakerTask extends BuildTask
echo "Generate files" . $this->lineBreak; echo "Generate files" . $this->lineBreak;
$this->generateFiles($fixtureFilePaths); $this->generateFiles($fixtureFilePaths);
if (!self::config()->get('doPutProtectedFilesInPublicStore')) { if (!FTFileMakerTask::config()->get('doPutProtectedFilesInPublicStore')) {
echo "Incorrectly putting protected files into public asset store on purpose" . $this->lineBreak; echo "Incorrectly putting protected files into public asset store on purpose" . $this->lineBreak;
$this->putProtectedFilesInPublicAssetStore(); $this->putProtectedFilesInPublicAssetStore();
} }
@ -276,7 +276,7 @@ class FTFileMakerTask extends BuildTask
$client = new Client(['base_uri' => $this->fixtureFileBaseUrl]); $client = new Client(['base_uri' => $this->fixtureFileBaseUrl]);
$fixtureFileNames = $this->fixtureFileNames; $fixtureFileNames = $this->fixtureFileNames;
if (self::config()->get('documentsOnly')) { if (FTFileMakerTask::config()->get('documentsOnly')) {
$fixtureFileNames = array_filter($fixtureFileNames ?? [], function($v) { $fixtureFileNames = array_filter($fixtureFileNames ?? [], function($v) {
return (bool) preg_match('%\.(docx|xlsx|pdf)$%', $v ?? ''); return (bool) preg_match('%\.(docx|xlsx|pdf)$%', $v ?? '');
}); });
@ -337,12 +337,12 @@ class FTFileMakerTask extends BuildTask
$folderCount = $this->folderCounts[$depth]; $folderCount = $this->folderCounts[$depth];
$fileCount = $this->fileCounts[$depth]; $fileCount = $this->fileCounts[$depth];
$doSetFolderPermissions = (bool) self::config()->get('doSetFolderPermissions'); $doSetFolderPermissions = (bool) FTFileMakerTask::config()->get('doSetFolderPermissions');
$doSetOldCreationDate = (bool) self::config()->get('doSetOldCreationDate'); $doSetOldCreationDate = (bool) FTFileMakerTask::config()->get('doSetOldCreationDate');
$doRandomlyPublish = (bool) self::config()->get('doRandomlyPublish'); $doRandomlyPublish = (bool) FTFileMakerTask::config()->get('doRandomlyPublish');
$uniqueImages = (bool) self::config()->get('uniqueImages'); $uniqueImages = (bool) FTFileMakerTask::config()->get('uniqueImages');
$watermarkPath = ModuleResourceLoader::singleton()->resolvePath( $watermarkPath = ModuleResourceLoader::singleton()->resolvePath(
'silverstripe/frameworktest: images/silverstripe.png' 'silverstripe/frameworktest: images/silverstripe.png'
); );
@ -424,7 +424,7 @@ class FTFileMakerTask extends BuildTask
} }
} }
if ($depth < self::config()->get('depth') - 1) { if ($depth < FTFileMakerTask::config()->get('depth') - 1) {
$this->generateFiles($fixtureFilePaths, $depth + 1, "{$prefix}-{$i}", $folder->ID); $this->generateFiles($fixtureFilePaths, $depth + 1, "{$prefix}-{$i}", $folder->ID);
} }
} }

View File

@ -43,9 +43,9 @@ class FTPageMakerTask extends BuildTask
* @config * @config
*/ */
private static $block_generators = [ private static $block_generators = [
'DNADesign\Elemental\Models\ElementContent' => [self::class, 'generateContentBlock'], 'DNADesign\Elemental\Models\ElementContent' => [FTPageMakerTask::class, 'generateContentBlock'],
'SilverStripe\ElementalBannerBlock\Block\BannerBlock' => [self::class, 'generateBannerBlock'], 'SilverStripe\ElementalBannerBlock\Block\BannerBlock' => [FTPageMakerTask::class, 'generateBannerBlock'],
'SilverStripe\ElementalFileBlock\Block\FileBlock' => [self::class, 'generateFileBlock'], 'SilverStripe\ElementalFileBlock\Block\FileBlock' => [FTPageMakerTask::class, 'generateFileBlock'],
]; ];
public function run($request) public function run($request)