class FluentExtension extends DataExtension (View source)

Basic fluent extension

When determining whether a field is localised, the following config options are checked in order:

  • translate (uninherited, for each class in the chain)
  • field_exclude
  • field_include
  • data_exclude
  • data_include

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

Properties

FluentExtension|DataObject $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

static private array $indexes_for_localised_table

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

static private array $field_include

Filter whitelist of fields to localise.

static private array $field_exclude

Filter blacklist of fields to localise.

static private $data_include

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

static private array $data_exclude

Filter blacklist of field types to localise.

static private bool $copy_to_locale_enabled

Enable copy to locale action in the localisation manager

static private bool $copy_from_locale_enabled

Enable copy from locale action in the localisation manager

static private bool $batch_actions_enabled

Enable batch actions in the edit form

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

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)

Augment a write-record request.

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 copy actions to each locale Note that permissions for these actions are resolved within the GridField components themselves

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

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)

Augment a write-record request.

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

See also

\TractorCow\Fluent\Extension\Traits\FluentObjectTrait::updateFluentCMSFields()

updateLocalisationTabConfig(GridFieldConfig $config)

Add copy actions to each locale Note that permissions for these actions are resolved within the GridField components themselves

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