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 Use class name instead of self #859

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
32 changes: 16 additions & 16 deletions src/Extension/FluentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [];
}

Expand All @@ -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)) {
Expand Down Expand Up @@ -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++;
}
}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
];

Expand All @@ -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');
}
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Extension/FluentFilteredExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
52 changes: 26 additions & 26 deletions src/Extension/FluentVersionedExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[][][]
*/
Expand All @@ -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 "
Expand All @@ -132,22 +132,22 @@ 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)
{
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);
}

/**
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand All @@ -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());
}

/**
Expand All @@ -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;
}

Expand All @@ -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
Expand All @@ -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;
}
}

Expand All @@ -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');
}
];

Expand All @@ -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');
}
];

Expand All @@ -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');
}
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Extension/Traits/FluentObjectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ trait FluentObjectTrait
* Add additional columns to localisation table
*
* @param $summaryColumns
* @see FluentObjectTrait::updateFluentCMSFields()
* @see self::updateFluentCMSFields()
*/
abstract public function updateLocalisationTabColumns(&$summaryColumns);

Expand Down
2 changes: 1 addition & 1 deletion src/Forms/CopyLocaleAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions src/Forms/LocaleToggleColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
}

Expand All @@ -49,7 +49,7 @@ public function augmentColumns($gridField, &$columns)
*/
public function getColumnsHandled($gridField)
{
return [self::COLUMN_NAME];
return [LocaleToggleColumn::COLUMN_NAME];
}

/**
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 */
Expand All @@ -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
);
}
Expand Down
Loading
Loading