From 6abbc9105ab2c3786dda8e0c0004c578bed49082 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 5 Jun 2024 16:36:55 +1200 Subject: [PATCH] ENH Use class name instead of self --- src/Extension/FluentExtension.php | 32 ++++++------- src/Extension/FluentFilteredExtension.php | 2 +- src/Extension/FluentVersionedExtension.php | 52 +++++++++++----------- src/Forms/CopyLocaleAction.php | 2 +- src/Forms/LocaleToggleColumn.php | 16 +++---- src/Model/LocalDateTime.php | 4 +- src/Model/Locale.php | 8 ++-- 7 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/Extension/FluentExtension.php b/src/Extension/FluentExtension.php index ff4f6820..1d16f522 100644 --- a/src/Extension/FluentExtension.php +++ b/src/Extension/FluentExtension.php @@ -247,7 +247,7 @@ public function getLocalisedFields($class = null) // List of DB fields $fields = DataObject::getSchema()->databaseFields($class, false); $filter = Config::inst()->get($class, 'translate', Config::UNINHERITED); - if ($filter === self::TRANSLATE_NONE || empty($fields)) { + if ($filter === FluentExtension::TRANSLATE_NONE || empty($fields)) { return $this->localisedFields[$class] = []; } @@ -273,7 +273,7 @@ protected function isFieldLocalised($field, $type, $class) { // Explicit per-table filter $filter = Config::inst()->get($class, 'translate', Config::UNINHERITED); - if ($filter === self::TRANSLATE_NONE) { + if ($filter === FluentExtension::TRANSLATE_NONE) { return false; } if ($filter && is_array($filter)) { @@ -405,7 +405,7 @@ protected function validateBaseConfig() $fluents = 0; $extensions = $this->owner->get_extensions(); foreach ($extensions as $extension) { - if (is_a($extension, self::class, true)) { + if (is_a($extension, FluentExtension::class, true)) { $fluents++; } } @@ -433,7 +433,7 @@ protected function validateChildConfig() $extensions = array_filter(array_values($extensions)); foreach ($extensions as $extension) { $extensionClass = Extension::get_classname_without_arguments($extension); - if (is_a($extensionClass, self::class, true)) { + if (is_a($extensionClass, FluentExtension::class, true)) { $name = get_class($this->owner); DB::alteration_message( "Invalid config: {$name} has FluentExtension, but this should be applied only on the base class", @@ -491,11 +491,11 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) // Resolve content inheritance (this drives what content is shown) $inheritanceMode = $this->getInheritanceMode(); - if ($inheritanceMode === self::INHERITANCE_MODE_EXACT) { + if ($inheritanceMode === FluentExtension::INHERITANCE_MODE_EXACT) { $joinAlias = $this->getLocalisedTable($this->owner->baseTable(), $locale->Locale); $where = sprintf('"%s"."ID" IS NOT NULL', $joinAlias); $query->addWhereAny($where); - } elseif ($inheritanceMode === self::INHERITANCE_MODE_FALLBACK) { + } elseif ($inheritanceMode === FluentExtension::INHERITANCE_MODE_FALLBACK) { $conditions = []; foreach ($locale->getChain() as $joinLocale) { @@ -809,7 +809,7 @@ protected function localiseManipulationTable(&$manipulation, $table, $localeTabl */ public function getLocalisedTable($tableName, $locale = '') { - $localisedTable = $tableName . '_' . self::SUFFIX; + $localisedTable = $tableName . '_' . FluentExtension::SUFFIX; if ($locale) { $localisedTable .= '_' . $locale; } @@ -1130,17 +1130,17 @@ protected function getInheritanceMode(): string // Detect legacy type if (is_bool($inheritanceMode)) { $inheritanceMode = $inheritanceMode - ? self::INHERITANCE_MODE_EXACT - : self::INHERITANCE_MODE_ANY; + ? FluentExtension::INHERITANCE_MODE_EXACT + : FluentExtension::INHERITANCE_MODE_ANY; } if (!in_array($inheritanceMode, [ - self::INHERITANCE_MODE_EXACT, - self::INHERITANCE_MODE_FALLBACK, - self::INHERITANCE_MODE_ANY, + FluentExtension::INHERITANCE_MODE_EXACT, + FluentExtension::INHERITANCE_MODE_FALLBACK, + FluentExtension::INHERITANCE_MODE_ANY, ])) { // Default mode - $inheritanceMode = self::INHERITANCE_MODE_ANY; + $inheritanceMode = FluentExtension::INHERITANCE_MODE_ANY; } return $inheritanceMode; @@ -1255,10 +1255,10 @@ public function updateLocalisationTabColumns(&$summaryColumns) } if ($object->RecordLocale()->IsDraft()) { - return _t(self::class . '.LOCALISED', 'Localised'); + return _t(FluentExtension::class . '.LOCALISED', 'Localised'); } - return _t(self::class . '.NOTLOCALISED', 'Not localised'); + return _t(FluentExtension::class . '.NOTLOCALISED', 'Not localised'); } ]; @@ -1275,7 +1275,7 @@ public function updateLocalisationTabColumns(&$summaryColumns) return $sourceLocale->getLongTitle(); } - return _t(self::class . '.NOSOURCE', 'No source'); + return _t(FluentExtension::class . '.NOSOURCE', 'No source'); } ]; } diff --git a/src/Extension/FluentFilteredExtension.php b/src/Extension/FluentFilteredExtension.php index b7dac66c..eaa8cf45 100644 --- a/src/Extension/FluentFilteredExtension.php +++ b/src/Extension/FluentFilteredExtension.php @@ -119,7 +119,7 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) } $table = $this->owner->baseTable(); - $filteredLocalesTable = $table . '_' . self::SUFFIX; + $filteredLocalesTable = $table . '_' . FluentFilteredExtension::SUFFIX; $query->addInnerJoin( $filteredLocalesTable, diff --git a/src/Extension/FluentVersionedExtension.php b/src/Extension/FluentVersionedExtension.php index 83ddc7df..96b1cf42 100644 --- a/src/Extension/FluentVersionedExtension.php +++ b/src/Extension/FluentVersionedExtension.php @@ -93,7 +93,7 @@ class FluentVersionedExtension extends FluentExtension implements Resettable * This is different from the above cache which caches the result per object - each array (keyed by locale & table) * will have ALL object IDs for that locale & table. * - * static::$idsInLocaleCache[ $locale ][ $table(.self::SUFFIX_LIVE) ][ $objectId ] = $objectId + * static::$idsInLocaleCache[ $locale ][ $table(.FluentVersionedExtension::SUFFIX_LIVE) ][ $objectId ] = $objectId * * @var int[][][] */ @@ -116,7 +116,7 @@ public function augmentDatabase() // Must see versioned if ($extension instanceof Versioned) { $seenVersioned = true; - } elseif ($extension instanceof self) { + } elseif ($extension instanceof FluentVersionedExtension) { if (!$seenVersioned) { throw new LogicException( "FluentVersionedExtension must be added AFTER Versioned extension. Check " @@ -132,8 +132,8 @@ public function augmentDatabase() protected function augmentDatabaseDontRequire($localisedTable) { DB::dont_require_table($localisedTable); - DB::dont_require_table($localisedTable . self::SUFFIX_LIVE); - DB::dont_require_table($localisedTable . self::SUFFIX_VERSIONS); + DB::dont_require_table($localisedTable . FluentVersionedExtension::SUFFIX_LIVE); + DB::dont_require_table($localisedTable . FluentVersionedExtension::SUFFIX_VERSIONS); } protected function augmentDatabaseRequireTable($localisedTable, $fields, $indexes) @@ -141,13 +141,13 @@ protected function augmentDatabaseRequireTable($localisedTable, $fields, $indexe DB::require_table($localisedTable, $fields, $indexes, false); // _Live record - DB::require_table($localisedTable . self::SUFFIX_LIVE, $fields, $indexes, false); + DB::require_table($localisedTable . FluentVersionedExtension::SUFFIX_LIVE, $fields, $indexes, false); // Merge fields and indexes with Fluent defaults $versionsFields = array_merge($this->defaultVersionsFields, $fields); $versionsIndexes = array_merge($indexes, $this->defaultVersionsIndexes); - DB::require_table($localisedTable . self::SUFFIX_VERSIONS, $versionsFields, $versionsIndexes, false); + DB::require_table($localisedTable . FluentVersionedExtension::SUFFIX_VERSIONS, $versionsFields, $versionsIndexes, false); } /** @@ -209,7 +209,7 @@ protected function rewriteVersionedTables(SQLSelect $query, array $tables, Local foreach ($tables as $tableName => $fields) { // Rename to _Versions suffixed versions $localisedTable = $this->getLocalisedTable($tableName); - $query->renameTable($localisedTable, $localisedTable . self::SUFFIX_VERSIONS); + $query->renameTable($localisedTable, $localisedTable . FluentVersionedExtension::SUFFIX_VERSIONS); // Add the chain of locale fallbacks $this->addLocaleFallbackChain($query, $tableName, $locale); @@ -229,7 +229,7 @@ protected function addLocaleFallbackChain(SQLSelect $query, $tableName, Locale $ foreach ($locale->getChain() as $joinLocale) { $joinAlias = $this->getLocalisedTable($tableName, $joinLocale->Locale); - $versionTable = $baseTable . self::SUFFIX_VERSIONS; + $versionTable = $baseTable . FluentVersionedExtension::SUFFIX_VERSIONS; $query->setJoinFilter( $joinAlias, @@ -250,7 +250,7 @@ protected function renameLocalisedTables(SQLSelect $query, array $tables) { foreach ($tables as $table => $fields) { $localisedTable = $this->getLocalisedTable($table); - $query->renameTable($localisedTable, $localisedTable . self::SUFFIX_LIVE); + $query->renameTable($localisedTable, $localisedTable . FluentVersionedExtension::SUFFIX_LIVE); } } @@ -295,13 +295,13 @@ public function augmentWrite(&$manipulation) $includedTables = $this->getLocalisedTables(); foreach ($includedTables as $table => $localisedFields) { // Localise both _Versions and _Live writes - foreach ([self::SUFFIX_LIVE, self::SUFFIX_VERSIONS] as $suffix) { + foreach ([FluentVersionedExtension::SUFFIX_LIVE, FluentVersionedExtension::SUFFIX_VERSIONS] as $suffix) { $versionedTable = $table . $suffix; $localisedTable = $this->getLocalisedTable($table) . $suffix; // Add extra case for "Version" column when localising Versions $localisedVersionFields = $localisedFields; - if ($suffix === self::SUFFIX_VERSIONS) { + if ($suffix === FluentVersionedExtension::SUFFIX_VERSIONS) { $localisedVersionFields = array_merge( $localisedVersionFields, array_keys($this->defaultVersionsFields) @@ -332,7 +332,7 @@ protected function getDeleteTableTarget($tableName, $locale = '') // Rewrite to _Live when deleting from live / unpublishing $table = parent::getDeleteTableTarget($tableName, $locale); if (Versioned::get_stage() === Versioned::LIVE) { - $table .= self::SUFFIX_LIVE; + $table .= FluentVersionedExtension::SUFFIX_LIVE; } return $table; } @@ -482,7 +482,7 @@ protected function isLocalisedInStage($stage, $locale = null) $baseTable = $this->owner->baseTable(); $table = $this->getLocalisedTable($baseTable); if ($stage === Versioned::LIVE) { - $table .= self::SUFFIX_LIVE; + $table .= FluentVersionedExtension::SUFFIX_LIVE; } // Check for a cached item in the full list of all objects. These are populated optimistically. @@ -529,7 +529,7 @@ public static function reset() */ public function onPrepopulateTreeDataCache($recordList = null, array $options = []) { - if (!Config::inst()->get(self::class, 'prepopulate_localecontent_cache')) { + if (!Config::inst()->get(FluentVersionedExtension::class, 'prepopulate_localecontent_cache')) { return; } @@ -539,7 +539,7 @@ public function onPrepopulateTreeDataCache($recordList = null, array $options = return; } - self::prepoulateIdsInLocale(FluentState::singleton()->getLocale(), $this->owner->baseClass()); + FluentVersionedExtension::prepoulateIdsInLocale(FluentState::singleton()->getLocale(), $this->owner->baseClass()); } /** @@ -558,7 +558,7 @@ public static function prepoulateIdsInLocale($locale, $dataObjectClass, $populat $table = $dataObject->getLocalisedTable($dataObject->baseTable()); // If we already have items then we've been here before... - if (isset(self::$idsInLocaleCache[$locale][$table])) { + if (isset(FluentVersionedExtension::$idsInLocaleCache[$locale][$table])) { return; } @@ -567,7 +567,7 @@ public static function prepoulateIdsInLocale($locale, $dataObjectClass, $populat $tables[] = $table; } if ($populateLive) { - $tables[] = $table . self::SUFFIX_LIVE; + $tables[] = $table . FluentVersionedExtension::SUFFIX_LIVE; } // Populate both the draft and live stages @@ -581,8 +581,8 @@ public static function prepoulateIdsInLocale($locale, $dataObjectClass, $populat $ids = $result->column('RecordID'); // We need to execute ourselves as the param is lost from the subSelect - self::$idsInLocaleCache[$locale][$table] = array_combine($ids, $ids); - self::$idsInLocaleCache[$locale][$table][static::CACHE_COMPLETE] = true; + FluentVersionedExtension::$idsInLocaleCache[$locale][$table] = array_combine($ids, $ids); + FluentVersionedExtension::$idsInLocaleCache[$locale][$table][static::CACHE_COMPLETE] = true; } } @@ -598,18 +598,18 @@ public function updateLocalisationTabColumns(&$summaryColumns) $recordLocale = $object->RecordLocale(); if ($recordLocale->getStagesDiffer()) { - return _t(self::class . '.MODIFIED', 'Modified'); + return _t(FluentVersionedExtension::class . '.MODIFIED', 'Modified'); } if ($recordLocale->IsPublished(true)) { - return _t(self::class . '.PUBLISHED', 'Published'); + return _t(FluentVersionedExtension::class . '.PUBLISHED', 'Published'); } if ($recordLocale->IsDraft()) { - return _t(self::class . '.DRAFT', 'Draft'); + return _t(FluentVersionedExtension::class . '.DRAFT', 'Draft'); } - return _t(self::class . '.NOTLOCALISED', 'Not localised'); + return _t(FluentVersionedExtension::class . '.NOTLOCALISED', 'Not localised'); } ]; @@ -626,7 +626,7 @@ public function updateLocalisationTabColumns(&$summaryColumns) return $sourceLocale->getLongTitle(); } - return _t(self::class . '.NOSOURCE', 'No source'); + return _t(FluentVersionedExtension::class . '.NOSOURCE', 'No source'); } ]; @@ -638,8 +638,8 @@ public function updateLocalisationTabColumns(&$summaryColumns) } return $object->RecordLocale()->IsPublished() - ? _t(self::class . '.LIVEYES', 'Yes') - : _t(self::class . '.LIVENO', 'No'); + ? _t(FluentVersionedExtension::class . '.LIVEYES', 'Yes') + : _t(FluentVersionedExtension::class . '.LIVENO', 'No'); } ]; } diff --git a/src/Forms/CopyLocaleAction.php b/src/Forms/CopyLocaleAction.php index 69103ea0..4a9bd727 100644 --- a/src/Forms/CopyLocaleAction.php +++ b/src/Forms/CopyLocaleAction.php @@ -166,7 +166,7 @@ public function getGroup($gridField, $record, $columnName) { $hasGroup = parent::getGroup($gridField, $record, $columnName); if ($hasGroup) { - return $this->isTo ? self::COPY_TO : self::COPY_FROM; + return $this->isTo ? CopyLocaleAction::COPY_TO : CopyLocaleAction::COPY_FROM; } return null; } diff --git a/src/Forms/LocaleToggleColumn.php b/src/Forms/LocaleToggleColumn.php index 6c4a88ef..4d950ed2 100644 --- a/src/Forms/LocaleToggleColumn.php +++ b/src/Forms/LocaleToggleColumn.php @@ -26,7 +26,7 @@ class LocaleToggleColumn implements GridField_SaveHandler, GridField_ColumnProvi public function augmentColumns($gridField, &$columns) { // Add "enabled in" column - if (in_array(self::COLUMN_NAME, $columns)) { + if (in_array(LocaleToggleColumn::COLUMN_NAME, $columns)) { return; } @@ -37,10 +37,10 @@ public function augmentColumns($gridField, &$columns) $columns, $localeIndex + 1, 0, - [self::COLUMN_NAME] + [LocaleToggleColumn::COLUMN_NAME] ); } else { - $columns[] = self::COLUMN_NAME; + $columns[] = LocaleToggleColumn::COLUMN_NAME; } } @@ -49,7 +49,7 @@ public function augmentColumns($gridField, &$columns) */ public function getColumnsHandled($gridField) { - return [self::COLUMN_NAME]; + return [LocaleToggleColumn::COLUMN_NAME]; } /** @@ -60,7 +60,7 @@ public function getColumnsHandled($gridField) */ public function getColumnContent($gridField, $locale, $columnName) { - if ($columnName !== self::COLUMN_NAME) { + if ($columnName !== LocaleToggleColumn::COLUMN_NAME) { return null; } @@ -96,8 +96,8 @@ public function handleSave(GridField $gridField, DataObjectInterface $record) $value = $gridField->Value(); // Keys for this value will be list of locales to enable - $enabledLocales = isset($value[self::COLUMN_NAME]) - ? array_keys($value[self::COLUMN_NAME]) + $enabledLocales = isset($value[LocaleToggleColumn::COLUMN_NAME]) + ? array_keys($value[LocaleToggleColumn::COLUMN_NAME]) : []; /** @var DataObject|FluentFilteredExtension $record */ @@ -112,7 +112,7 @@ protected function getFieldName(GridField $grid, Locale $locale) return sprintf( '%s[%s][%s]', $grid->getName(), - self::COLUMN_NAME, + LocaleToggleColumn::COLUMN_NAME, $locale->ID ); } diff --git a/src/Model/LocalDateTime.php b/src/Model/LocalDateTime.php index 932ae1c2..746900af 100644 --- a/src/Model/LocalDateTime.php +++ b/src/Model/LocalDateTime.php @@ -40,7 +40,7 @@ public function getTimezone(): ?string * @param string|null $timezone * @return $this */ - public function setTimezone(?string $timezone): self + public function setTimezone(?string $timezone): LocalDateTime { if ($timezone && !in_array($timezone, timezone_identifiers_list())) { throw new InvalidArgumentException("Invalid timezone {$timezone}"); @@ -90,7 +90,7 @@ public function setValue($value, $record = null, $markChanged = true) */ public function getLocalValue(): string { - return $this->Format(self::ISO_DATETIME); + return $this->Format(LocalDateTime::ISO_DATETIME); } /** Assign a value that's already in the current locale diff --git a/src/Model/Locale.php b/src/Model/Locale.php index e97715db..b7b5f1ef 100644 --- a/src/Model/Locale.php +++ b/src/Model/Locale.php @@ -253,7 +253,7 @@ public function getBadgeLabel() public function getHrefLang() { if ($this->UseDefaultCode) { - return self::X_DEFAULT; + return Locale::X_DEFAULT; } return strtolower(i18n::convert_rfc1766($this->Locale)); } @@ -307,7 +307,7 @@ public function getCMSFields() )), CheckboxField::create( 'UseDefaultCode', - _t(__CLASS__ . '.USE_X_DEFAULT', 'Use {code} as SEO language code (treat as global)', ['code' => self::X_DEFAULT]) + _t(__CLASS__ . '.USE_X_DEFAULT', 'Use {code} as SEO language code (treat as global)', ['code' => Locale::X_DEFAULT]) ) ->setDescription(_t( __CLASS__ . '.USE_X_DEFAULT_DESCRIPTION', @@ -630,7 +630,7 @@ public function RecordLocale() */ public function getLocaleEditPermission() { - $prefix = self::CMS_ACCESS_FLUENT_LOCALE; + $prefix = Locale::CMS_ACCESS_FLUENT_LOCALE; return "{$prefix}{$this->Locale}"; } @@ -640,7 +640,7 @@ public function providePermissions() $category = _t(__CLASS__ . '.PERMISSION', 'Localisation'); $permissions = [ // @todo - Actually implement this check on those actions - self::CMS_ACCESS_MULTI_LOCALE => [ + Locale::CMS_ACCESS_MULTI_LOCALE => [ 'name' => _t( __CLASS__ . '.MULTI_LOCALE', 'Access to multi-locale actions (E.g. save in all locales)'