Skip to content

Commit

Permalink
ENH Use class name instead of self
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 5, 2024
1 parent 2a6def8 commit 941be1a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion code/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public function data()

public function scaffoldSearchField()
{
return DropdownField::create('CompanyID', 'Company', self::get()->map())->setEmptyString('');
return DropdownField::create('CompanyID', 'Company', Company::get()->map())->setEmptyString('');
}

}
18 changes: 9 additions & 9 deletions code/GridFieldArbitraryData/ArbitraryDataAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ protected function init()

// accessing the admin directly
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}");
}
}
Expand All @@ -69,12 +69,12 @@ public function getList()
$list = ArrayList::create();

switch ($this->tab) {
case self::TAB_ARRAYDATA:
foreach (self::getInitialRecords() as $stub) {
case ArbitraryDataAdmin::TAB_ARRAYDATA:
foreach (ArbitraryDataAdmin::getInitialRecords() as $stub) {
$list->add(ArrayData::create($stub));
}
break;
case self::TAB_CUSTOM_MODEL:
case ArbitraryDataAdmin::TAB_CUSTOM_MODEL:
$rawData = SQLSelect::create()->setFrom(ArbitraryDataModel::TABLE_NAME)->execute();
foreach ($rawData as $record) {
$list->add(ArbitraryDataModel::create($record));
Expand Down Expand Up @@ -105,14 +105,14 @@ public static function getInitialRecords()

protected function getGridFieldConfig(): GridFieldConfig
{
if ($this->tab === self::TAB_CUSTOM_MODEL) {
if ($this->tab === ArbitraryDataAdmin::TAB_CUSTOM_MODEL) {
$config = GridFieldConfig_RecordEditor::create();
} else {
// This is effectively the same as a GridFieldConfig_RecordViewer, but without removing the GridFieldFilterHeader.
$config = GridFieldConfig_Base::create();
$config->addComponent(GridFieldViewButton::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));
$fields = array_map(fn ($name) => $name === 'ID' ? HiddenField::create($name) : TextField::create($name), $fieldNames);
$config->getComponentByType(GridFieldDetailForm::class)->setFields(FieldList::create($fields));
Expand Down Expand Up @@ -188,8 +188,8 @@ public function getEditForm($id = null, $fields = null)
protected function getManagedTabs()
{
$tabs = [
self::TAB_ARRAYDATA => 'ArrayData',
self::TAB_CUSTOM_MODEL => 'Custom Model',
ArbitraryDataAdmin::TAB_ARRAYDATA => 'ArrayData',
ArbitraryDataAdmin::TAB_CUSTOM_MODEL => 'Custom Model',
];
$forms = new ArrayList();

Expand Down
8 changes: 4 additions & 4 deletions code/GridFieldArbitraryData/ArbitraryDataModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function write()
}

// 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) {
if (!array_key_exists($fieldName, $dbColumns)) {
unset($record[$fieldName]);
Expand All @@ -76,11 +76,11 @@ public function write()
if (!$isNew) {
$manipulation['id'] = $this->ID;
}
DB::manipulate([self::TABLE_NAME => $manipulation]);
DB::manipulate([ArbitraryDataModel::TABLE_NAME => $manipulation]);

if ($isNew) {
// 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);
}
}

Expand All @@ -89,7 +89,7 @@ public function delete()
if (!$this->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;
}

Expand Down
4 changes: 2 additions & 2 deletions code/TestPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function canCreate($member = null, $context = array())

public function requireDefaultRecords()
{
if (static::class === self::class) {
if (static::class === TestPage::class) {
return;
}

Expand All @@ -46,7 +46,7 @@ public function requireDefaultRecords()
Member::actAs($defaultAdminService->findOrCreateDefaultAdmin(), function () {
// Create actual page
$page = new static();
$page->Title = str_replace(self::class, "", static::class);
$page->Title = str_replace(TestPage::class, "", static::class);
$page->ShowInMenus = 0;
$parent = static::getOrCreateParentPage();
$page->ParentID = $parent->ID;
Expand Down
20 changes: 10 additions & 10 deletions code/tasks/FTFileMakerTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function run($request)
return (int) trim($int ?? '');
}, $counts ?? []);
} else {
$this->fileCounts = self::config()->get('fileCountByDepth');
$this->fileCounts = FTFileMakerTask::config()->get('fileCountByDepth');
}

$folderCounts = $request->getVar('folderCounts');
Expand All @@ -238,21 +238,21 @@ public function run($request)
return (int) trim($int ?? '');
}, $counts ?? []);
} else {
$this->folderCounts = self::config()->get('folderCountByDepth');
$this->folderCounts = FTFileMakerTask::config()->get('folderCountByDepth');
}

echo "Downloading fixtures" . $this->lineBreak;
$fixtureFilePaths = $this->downloadFixtureFiles();

if (!self::config()->get('documentsOnly')) {
if (!FTFileMakerTask::config()->get('documentsOnly')) {
echo "Generate thumbnails" . $this->lineBreak;
$this->generateThumbnails($fixtureFilePaths);
}

echo "Generate files" . $this->lineBreak;
$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;
$this->putProtectedFilesInPublicAssetStore();
}
Expand All @@ -276,7 +276,7 @@ protected function downloadFixtureFiles()
$client = new Client(['base_uri' => $this->fixtureFileBaseUrl]);

$fixtureFileNames = $this->fixtureFileNames;
if (self::config()->get('documentsOnly')) {
if (FTFileMakerTask::config()->get('documentsOnly')) {
$fixtureFileNames = array_filter($fixtureFileNames ?? [], function($v) {
return (bool) preg_match('%\.(docx|xlsx|pdf)$%', $v ?? '');
});
Expand Down Expand Up @@ -337,12 +337,12 @@ protected function generateFiles($fixtureFilePaths, $depth = 0, $prefix = "0", $
$folderCount = $this->folderCounts[$depth];
$fileCount = $this->fileCounts[$depth];

$doSetFolderPermissions = (bool) self::config()->get('doSetFolderPermissions');
$doSetFolderPermissions = (bool) FTFileMakerTask::config()->get('doSetFolderPermissions');

$doSetOldCreationDate = (bool) self::config()->get('doSetOldCreationDate');
$doRandomlyPublish = (bool) self::config()->get('doRandomlyPublish');
$doSetOldCreationDate = (bool) FTFileMakerTask::config()->get('doSetOldCreationDate');
$doRandomlyPublish = (bool) FTFileMakerTask::config()->get('doRandomlyPublish');

$uniqueImages = (bool) self::config()->get('uniqueImages');
$uniqueImages = (bool) FTFileMakerTask::config()->get('uniqueImages');
$watermarkPath = ModuleResourceLoader::singleton()->resolvePath(
'silverstripe/frameworktest: images/silverstripe.png'
);
Expand Down Expand Up @@ -424,7 +424,7 @@ protected function generateFiles($fixtureFilePaths, $depth = 0, $prefix = "0", $
}
}

if ($depth < self::config()->get('depth') - 1) {
if ($depth < FTFileMakerTask::config()->get('depth') - 1) {
$this->generateFiles($fixtureFilePaths, $depth + 1, "{$prefix}-{$i}", $folder->ID);
}
}
Expand Down
6 changes: 3 additions & 3 deletions code/tasks/FTPageMakerTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class FTPageMakerTask extends BuildTask
* @config
*/
private static $block_generators = [
'DNADesign\Elemental\Models\ElementContent' => [self::class, 'generateContentBlock'],
'SilverStripe\ElementalBannerBlock\Block\BannerBlock' => [self::class, 'generateBannerBlock'],
'SilverStripe\ElementalFileBlock\Block\FileBlock' => [self::class, 'generateFileBlock'],
'DNADesign\Elemental\Models\ElementContent' => [FTPageMakerTask::class, 'generateContentBlock'],
'SilverStripe\ElementalBannerBlock\Block\BannerBlock' => [FTPageMakerTask::class, 'generateBannerBlock'],
'SilverStripe\ElementalFileBlock\Block\FileBlock' => [FTPageMakerTask::class, 'generateFileBlock'],
];

public function run($request)
Expand Down

0 comments on commit 941be1a

Please sign in to comment.