class FluentVersionedExtension extends FluentExtension implements Resettable (View source)

Extension for versioned localised objects

Important: If adding this to a custom object, this extension must be added AFTER the versioned extension. Use yaml after to enforce this

Traits

Shared functionality between both FluentExtension and FluentFilteredExtension

Constants

SUFFIX

The table suffix that will be applied to create localisation tables

TRANSLATE_NONE

translate config key to disable localisations for this table

INHERITANCE_MODE_EXACT

Content inheritance - content will be served from the following sources in this order: current locale

INHERITANCE_MODE_FALLBACK

Content inheritance - content will be served from the following sources in this order: current locale, fallback locale

INHERITANCE_MODE_ANY

Content inheritance - content will be served from the following sources in this order: current locale, fallback locale, base record

SUFFIX_LIVE

Live table suffix

SUFFIX_VERSIONS

Versions table suffix

CACHE_COMPLETE

Indicates that record is missing in this locale and the cache search for it is complete so we can avoid multiple lookups of a missing record

Properties

DataObject|FluentVersionedExtension $owner
static private array $db_for_localised_table

DB fields to be used added in when creating a localised version of the owner's table

from  FluentExtension
static private array $indexes_for_localised_table

Indexes to create on a localised version of the owner's table

from  FluentExtension
static private array $field_include

Filter whitelist of fields to localise.

from  FluentExtension
static private array $field_exclude

Filter blacklist of fields to localise.

from  FluentExtension
static private $data_include

Filter whitelist of field types to localise Note: Blacklist takes priority over whitelist.

from  FluentExtension
static private array $data_exclude

Filter blacklist of field types to localise.

from  FluentExtension
static private bool $copy_to_locale_enabled

Enable copy to locale action in the localisation manager

from  FluentExtension
static private bool $copy_from_locale_enabled

Enable copy from locale action in the localisation manager

from  FluentExtension
static private bool $batch_actions_enabled

Enable batch actions in the edit form

from  FluentExtension
static private bool $localise_actions_enabled

Enable localise actions (copy to draft, copy & publish and Localise actions) these actions can be used to localise page content directly via main page actions

from  FluentExtension
static private bool $prepopulate_localecontent_cache

Used to enable or disable the prepopulation of the locale content cache Defaults to true.

Methods

__construct()

No description

static 
add_to_class(string $class, string $extensionClass, mixed $args = null)

Called when this extension is added to a particular class

setOwner(object $owner)

Set the owner of this extension.

mixed
withOwner(mixed $owner, callable $callback, array $args = [])

Temporarily modify the owner. The original owner is ensured to be restored

clearOwner()

Clear the current owner, and restore extension to the state prior to the last setOwner()

object
getOwner()

Returns the owner of this extension.

static string
get_classname_without_arguments(string $extensionStr)

Helper method to strip eval'ed arguments from a string that's passed to {@link DataObject::$extensions} or {@link Object::add_extension()}.

mixed
invokeExtension(object $owner, string $method, array ...$arguments)

Invoke extension point. This will prefer explicit extend prefixed methods.

validate(ValidationResult $validationResult)

Hook for extension-specific validation.

augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)

Edit the given query object to support queries for this extension

augmentDatabase()

Update the database schema as required by this extension.

augmentWrite(array $manipulation)

Apply versioning to write

onBeforeWrite()

Force all changes, since we may need to cross-publish unchanged records between locales. Without this, loading a page in a different locale and pressing "save" won't actually make the record available in this locale.

onAfterWrite()

No description

onBeforeDelete()

Extend the owner's onBeforeDelete() logic

onAfterDelete()

Extend the owner's onAfterDelete() logic

requireDefaultRecords()

Extend the owner's requireDefaultRecords() logic

populateDefaults()

Extend the owner's populateDefaults() logic

onAfterBuild()

Extend the owner's onAfterBuild() logic

bool|null
can(Member $member)

Influence the owner's can() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

bool|null
canEdit(Member $member)

Influence the owner's canEdit() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

bool|null
canDelete(Member $member)

Influence the owner's canDelete() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

bool|null
canCreate(Member $member)

Influence the owner's canCreate() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

array
extraStatics(string $class = null, string $extension = null)

Define extra database fields

updateCMSFields(FieldList $fields)

No description

void
updateCMSCompositeValidator(CompositeValidator $compositeValidator)

This function is used to provide modifications to the Validators used on a DataObject.

updateFrontEndFields(FieldList $fields)

This function is used to provide modifications to the form used for front end forms. {@link DataObject->getFrontEndFields()}

updateCMSActions(FieldList $actions)

This is used to provide modifications to the form actions used in the CMS. {@link DataObject->getCMSActions()}.

updateSummaryFields(array $fields)

this function is used to provide modifications to the summary fields in CMS by the extension By default, the summaryField() of its owner will merge more fields defined in the extension's $extra_fields['summary_fields']

updateFieldLabels(array $labels)

this function is used to provide modifications to the fields labels in CMS by the extension By default, the fieldLabels() of its owner will merge more fields defined in the extension's $extra_fields['field_labels']

updateDeleteTables(array $queriedTables)

Override delete behaviour.

updateLocalisationTabColumns($summaryColumns)

No description

updateLocalisationTabConfig(GridFieldConfig $config)

Add versioning extensions for gridfield

LinkedLocales()

Gets list of all Locale dataobjects, linked to this record

augmentDataQueryCreation(SQLSelect $query, DataQuery $dataQuery)

Amend freshly created DataQuery objects with the current locale and frontend status

array
getLocalisedFields(string $class = null)

Get list of fields that are localised

array
getLocalisedTables()

Get all database tables in the class ancestry and their respective translatable fields

string
getLocalisedTable(string $tableName, string $locale = '')

Get the localised table name with the localised suffix and optionally with a locale suffix for aliases

string
deleteTableTarget(string $tableName, string $locale = '')

Public accessor for getDeleteTableTarget

updateFluentLocalisedFields(FieldList $fields)

Add / refresh fluent badges to all localised fields.

Locale|null
getSourceLocale()

Returns the source locale that will display the content for this record

Locales()

Templatable list of all locale information for this record

LocaleInformation(string $locale = null)

Retrieves information about this object in the specified locale

array
getLocaleInstances()

Get list of locales where record is localised in draft mode

string
BaseURLForLocale(string $locale)

Determine the baseurl within a specified $locale.

string
cacheKeyComponent()

Ensure has_one cache is segmented by locale

updateFluentCMSField(FormField $field)

Add fluent tooltip to given field.

getSelectedLanguage()

Returns the selected language

bool
existsInLocale(string $locale = null)

Check if this record exists (in either state) in this locale

bool
getLocalisedCopyActive()

No description

setLocalisedCopyActive(bool $active)

No description

mixed
withLocalisedCopyState(callable $callback)

Localised copy global state manipulation useful for disabling localised copy feature in parts of the code

void
copyToLocale(string $toLocale)

Copy data object content from current locale to the target locale

bool
isDraftedInLocale(string $locale = null)

Check if this record is saved in this locale

bool
isPublishedInLocale(string $locale = null)

Check if this record is published in this locale

bool
stagesDifferInLocale(string|null $locale = null)

Check if this record has modifications in this locale Fluent friendly version of see Versioned::stagesDiffer()

flushCache()

Clear internal static property caches

void
flushVersionsCache()

No description

static 
reset()

Reset the local cache of this object

onPrepopulateTreeDataCache(DataList|array $recordList = null, array $options = [])

Hook into {@link Hierarchy::prepopulateTreeDataCache}.

static 
prepoulateIdsInLocale(string $locale, string $dataObjectClass, bool $populateLive = true, bool $populateDraft = true)

Prepopulate the cache of IDs in a locale, to optimise batch calls to isLocalisedInStage.

void
updateStagesDiffer(bool $stagesDiffer)

Extension point in see Versioned::stagesDiffer()

void
updateIsArchived(bool $isArchived)

Localise archived state Extension point in see Versioned::isArchived()

bool|null
isArchivedInLocale(string|null $locale = null)

No description

bool|null
hasArchiveInLocale(string $locale = null)

Check if the record has previously existed in a locale

void
augmentMaxVersionSubSelect(SQLSelect $subSelect, DataQuery $dataQuery, bool $shouldApplySubSelectAsCondition)

Localise max version lookup Extension point in see Versioned::prepareMaxVersionSubSelect()

void
updatePrePopulateVersionNumberCache(array $versions, DataObject|string $class, string $stage, array|null $idList)

Localise version cache populate Extension point in see Versioned::prepopulate_versionnumber_cache()

void
updateGetVersionNumberByStage(int|null $version, DataObject|string $class, string $stage, int $id, bool $cache)

Localise version lookup Extension point in see Versioned::get_versionnumber_by_stage()

Details

__construct()

static add_to_class(string $class, string $extensionClass, mixed $args = null)

Called when this extension is added to a particular class

Parameters

string $class
string $extensionClass
mixed $args

setOwner(object $owner)

Set the owner of this extension.

Parameters

object $owner

The owner object

mixed withOwner(mixed $owner, callable $callback, array $args = [])

Temporarily modify the owner. The original owner is ensured to be restored

Parameters

mixed $owner

Owner to set

callable $callback

Callback to invoke

array $args

Args to pass to callback

Return Value

mixed

clearOwner()

Clear the current owner, and restore extension to the state prior to the last setOwner()

object getOwner()

Returns the owner of this extension.

Return Value

object

static string get_classname_without_arguments(string $extensionStr)

Helper method to strip eval'ed arguments from a string that's passed to {@link DataObject::$extensions} or {@link Object::add_extension()}.

Parameters

string $extensionStr

E.g. "Versioned('Stage','Live')"

Return Value

string

Extension classname, e.g. "Versioned"

mixed invokeExtension(object $owner, string $method, array ...$arguments)

Invoke extension point. This will prefer explicit extend prefixed methods.

Parameters

object $owner
string $method
array ...$arguments

Return Value

mixed

validate(ValidationResult $validationResult)

Hook for extension-specific validation.

Parameters

ValidationResult $validationResult

Local validation result

Exceptions

ValidationException

augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)

Edit the given query object to support queries for this extension

Parameters

SQLSelect $query

Query to augment.

DataQuery $dataQuery

Container DataQuery for this SQLSelect

augmentDatabase()

Update the database schema as required by this extension.

When duplicating a table's structure, remember to duplicate the create options as well. See {@link Versioned->augmentDatabase} for an example.

augmentWrite(array $manipulation)

Apply versioning to write

Parameters

array $manipulation

Array of operations to augment.

onBeforeWrite()

Force all changes, since we may need to cross-publish unchanged records between locales. Without this, loading a page in a different locale and pressing "save" won't actually make the record available in this locale.

onAfterWrite()

Exceptions

ValidationException

onBeforeDelete()

Extend the owner's onBeforeDelete() logic

See {@link DataObject::onBeforeDelete()} for context.

onAfterDelete()

Extend the owner's onAfterDelete() logic

See {@link DataObject::onAfterDelete()} for context.

requireDefaultRecords()

Extend the owner's requireDefaultRecords() logic

See {@link DataObject::requireDefaultRecords()} for context.

populateDefaults()

Extend the owner's populateDefaults() logic

See {@link DataObject::populateDefaults()} for context.

onAfterBuild()

Extend the owner's onAfterBuild() logic

See {@link DataObject::onAfterBuild()} for context.

bool|null can(Member $member)

Influence the owner's can() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

See {@link DataObject::can()} and {@link DataObject::extendedCan()} for context.

Parameters

Member $member

Return Value

bool|null

bool|null canEdit(Member $member)

Influence the owner's canEdit() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

See {@link DataObject::canEdit()} and {@link DataObject::extendedCan()} for context.

Parameters

Member $member

Return Value

bool|null

bool|null canDelete(Member $member)

Influence the owner's canDelete() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

See {@link DataObject::canDelete()} and {@link DataObject::extendedCan()} for context.

Parameters

Member $member

Return Value

bool|null

bool|null canCreate(Member $member)

Influence the owner's canCreate() permission check value to be disallowed (false), allowed (true) if no other processed results are to disallow, or open (null) to not affect the outcome.

See {@link DataObject::canCreate()} and {@link DataObject::extendedCan()} for context.

Parameters

Member $member

Return Value

bool|null

array extraStatics(string $class = null, string $extension = null)

Define extra database fields

Return a map where the keys are db, has_one, etc, and the values are additional fields/relations to be defined.

Parameters

string $class

since this method might be called on the class directly

string $extension

since this can help to extract parameters to help set indexes

Return Value

array

Returns a map where the keys are db, has_one, etc, and the values are additional fields/relations to be defined.

updateCMSFields(FieldList $fields)

Parameters

FieldList $fields

FieldList with a contained TabSet

void updateCMSCompositeValidator(CompositeValidator $compositeValidator)

This function is used to provide modifications to the Validators used on a DataObject.

Caution: Use {@link CompositeValidator->addValidator()} to add Validators.

Parameters

CompositeValidator $compositeValidator

Return Value

void

updateFrontEndFields(FieldList $fields)

This function is used to provide modifications to the form used for front end forms. {@link DataObject->getFrontEndFields()}

Caution: Use {@link FieldList->push()} to add fields.

Parameters

FieldList $fields

FieldList without TabSet nesting

updateCMSActions(FieldList $actions)

This is used to provide modifications to the form actions used in the CMS. {@link DataObject->getCMSActions()}.

Parameters

FieldList $actions

FieldList

updateSummaryFields(array $fields)

this function is used to provide modifications to the summary fields in CMS by the extension By default, the summaryField() of its owner will merge more fields defined in the extension's $extra_fields['summary_fields']

Parameters

array $fields

Array of field names

updateFieldLabels(array $labels)

this function is used to provide modifications to the fields labels in CMS by the extension By default, the fieldLabels() of its owner will merge more fields defined in the extension's $extra_fields['field_labels']

Parameters

array $labels

Array of field labels

updateDeleteTables(array $queriedTables)

Override delete behaviour.

Hooks into {see \TractorCow\Fluent\Model\Delete\DataObject::delete()}

Parameters

array $queriedTables

updateLocalisationTabColumns($summaryColumns)

Parameters

$summaryColumns

updateLocalisationTabConfig(GridFieldConfig $config)

Add versioning extensions for gridfield

Parameters

GridFieldConfig $config

ArrayList|Locale[] LinkedLocales()

Gets list of all Locale dataobjects, linked to this record

Return Value

ArrayList|Locale[]

See also

Locale::RecordLocale

augmentDataQueryCreation(SQLSelect $query, DataQuery $dataQuery)

Amend freshly created DataQuery objects with the current locale and frontend status

Parameters

SQLSelect $query
DataQuery $dataQuery

array getLocalisedFields(string $class = null)

Get list of fields that are localised

Parameters

string $class

Class to get fields for (if parent)

Return Value

array

array getLocalisedTables()

Get all database tables in the class ancestry and their respective translatable fields

Return Value

array

string getLocalisedTable(string $tableName, string $locale = '')

Get the localised table name with the localised suffix and optionally with a locale suffix for aliases

Parameters

string $tableName
string $locale

Return Value

string

string deleteTableTarget(string $tableName, string $locale = '')

Public accessor for getDeleteTableTarget

Parameters

string $tableName
string $locale

Return Value

string

updateFluentLocalisedFields(FieldList $fields)

Add / refresh fluent badges to all localised fields.

Note: Idempotent and safe to call multiple times

Parameters

FieldList $fields

Locale|null getSourceLocale()

Returns the source locale that will display the content for this record

Return Value

Locale|null

ArrayList|RecordLocale[] Locales()

Templatable list of all locale information for this record

Return Value

ArrayList|RecordLocale[]

RecordLocale LocaleInformation(string $locale = null)

Retrieves information about this object in the specified locale

Parameters

string $locale

The locale (code) information to request, or null to use the default locale

Return Value

RecordLocale

array getLocaleInstances()

Get list of locales where record is localised in draft mode

Return Value

array

string BaseURLForLocale(string $locale)

Determine the baseurl within a specified $locale.

Parameters

string $locale

Locale

Return Value

string

string cacheKeyComponent()

Ensure has_one cache is segmented by locale

Return Value

string

updateFluentCMSField(FormField $field)

Add fluent tooltip to given field.

You can use this to add fluent tag to custom fields.

Parameters

FormField $field

RecordLocale getSelectedLanguage()

Returns the selected language

Return Value

RecordLocale

bool existsInLocale(string $locale = null)

Check if this record exists (in either state) in this locale

Parameters

string $locale

Return Value

bool

bool getLocalisedCopyActive()

Return Value

bool

DataObject setLocalisedCopyActive(bool $active)

Parameters

bool $active

Return Value

DataObject

mixed withLocalisedCopyState(callable $callback)

Localised copy global state manipulation useful for disabling localised copy feature in parts of the code

Parameters

callable $callback

Return Value

mixed

void copyToLocale(string $toLocale)

Copy data object content from current locale to the target locale

Parameters

string $toLocale

Return Value

void

Exceptions

ValidationException

bool isDraftedInLocale(string $locale = null)

Check if this record is saved in this locale

Parameters

string $locale

Return Value

bool

bool isPublishedInLocale(string $locale = null)

Check if this record is published in this locale

Parameters

string $locale

Return Value

bool

bool stagesDifferInLocale(string|null $locale = null)

Check if this record has modifications in this locale Fluent friendly version of see Versioned::stagesDiffer()

Parameters

string|null $locale

Return Value

bool

flushCache()

Clear internal static property caches

void flushVersionsCache()

Return Value

void

static reset()

Reset the local cache of this object

onPrepopulateTreeDataCache(DataList|array $recordList = null, array $options = [])

Hook into {@link Hierarchy::prepopulateTreeDataCache}.

Parameters

DataList|array $recordList

The list of records to prepopulate caches for. Null for all records.

array $options

A map of hints about what should be cached. "numChildrenMethod" and "childrenMethod" are allowed keys.

static prepoulateIdsInLocale(string $locale, string $dataObjectClass, bool $populateLive = true, bool $populateDraft = true)

Prepopulate the cache of IDs in a locale, to optimise batch calls to isLocalisedInStage.

Parameters

string $locale
string $dataObjectClass
bool $populateLive
bool $populateDraft

void updateStagesDiffer(bool $stagesDiffer)

Extension point in see Versioned::stagesDiffer()

Parameters

bool $stagesDiffer

Return Value

void

void updateIsArchived(bool $isArchived)

Localise archived state Extension point in see Versioned::isArchived()

Parameters

bool $isArchived

Return Value

void

bool|null isArchivedInLocale(string|null $locale = null)

Parameters

string|null $locale

Return Value

bool|null

bool|null hasArchiveInLocale(string $locale = null)

Check if the record has previously existed in a locale

Parameters

string $locale

Return Value

bool|null

void augmentMaxVersionSubSelect(SQLSelect $subSelect, DataQuery $dataQuery, bool $shouldApplySubSelectAsCondition)

Localise max version lookup Extension point in see Versioned::prepareMaxVersionSubSelect()

Parameters

SQLSelect $subSelect
DataQuery $dataQuery
bool $shouldApplySubSelectAsCondition

Return Value

void

void updatePrePopulateVersionNumberCache(array $versions, DataObject|string $class, string $stage, array|null $idList)

Localise version cache populate Extension point in see Versioned::prepopulate_versionnumber_cache()

Parameters

array $versions
DataObject|string $class
string $stage
array|null $idList

Return Value

void

void updateGetVersionNumberByStage(int|null $version, DataObject|string $class, string $stage, int $id, bool $cache)

Localise version lookup Extension point in see Versioned::get_versionnumber_by_stage()

Parameters

int|null $version
DataObject|string $class
string $stage
int $id
bool $cache

Return Value

void