Contao Utils Bundle

DcaUtil
in package

Table of Contents

Constants

AUTHOR_TYPE_MEMBER  = 'member'
AUTHOR_TYPE_NONE  = 'none'
AUTHOR_TYPE_SESSION  = 'session'
AUTHOR_TYPE_USER  = 'user'
PROPERTY_AUTHOR  = 'author'
PROPERTY_AUTHOR_TYPE  = 'authorType'
PROPERTY_SESSION_ID  = 'sessionID'

Properties

$container  : ContainerInterface
$framework  : ContaoFrameworkInterface
$connection  : Connection
$routingUtil  : RoutingUtil

Methods

__construct()  : mixed
activateNotificationType()  : mixed
addAliasToDca()  : mixed
Adds an alias field to the dca and to the desired palettes.
addAuthorFieldAndCallback()  : mixed
addOverridableFields()  : mixed
Adds an override selector to every field in $fields to the dca associated with $destinationTable.
aliasExist()  : bool
Return if the current alias already exist in table.
doGenerateDcOperationsButtons()  : mixed
flattenPaletteForSubEntities()  : mixed
This function transforms an entity's palette (that can also contain sub palettes and concatenated type selectors) to a flatten palette where every field can be overridden.
generateAlias()  : string
Generate an alias with unique check.
generateDcOperationsButtons()  : mixed
generateSitemap()  : mixed
getArchiveModalEditLink()  : string
Get a contao backend modal archive edit link.
getAuthorNameByUserId()  : mixed
getAuthorNameLinkByUserId()  : mixed
getConfigByArrayOrCallbackOrFunction()  : mixed|null
Retrieves an array from a dca config (in most cases eval) in the following priorities:.
getCurrentPaletteName()  : string|null
Taken from \Contao\DataContainer.
getDataContainers()  : array<string|int, mixed>
Returns (nearly) all registered datacontainers as array.
getDCTable()  : DC_Table_Utils
Mostly used for Form::prepareSpecialValueForOutput().
getEditLink()  : string
Get a contao backend modal edit link.
getFieldLabel()  : mixed
getFields()  : array<string|int, mixed>
Returns a list of fields as an option array for dca fields.
getLocalizedFieldName()  : mixed
getModalEditLink()  : string
Get a contao backend modal edit link.
getNewNotificationTypeArray()  : array<string|int, mixed>
getNewSortingPosition()  : array<string|int, mixed>
Returns the set of pid and sorting to be used in an sql update statement. Also updates the existing records according to the usage.
getOverridableProperty()  : mixed
Retrieves a property of given contao model instances by *ascending* priority, i.e. the last instance of $instances will have the highest priority.
getPopupWizardLink()  : string
Get a contao backend popup link.
getRenderedDiff()  : mixed
getSubPaletteFieldSelector()  : string
Returns the selector of the sub palette a field is placed in. Currently doesn't support fields in multiple sub palettes.
getTranslatedModuleNameByTable()  : mixed
isDcMultilingual()  : mixed
isDcMultilingual3()  : mixed
isSubPaletteField()  : bool
Returns true if the field is in at least one sub palette.
loadDc()  : mixed
Load a data container in a testable way.
loadLanguageFile()  : mixed
Load a language file in a testable way.
modifyAuthorPaletteOnLoad()  : mixed
prepareRowEntryForList()  : mixed
setAuthorIDOnCreate()  : mixed
setDateAdded()  : mixed
Sets the current date as the date added -> usually used on submit.
setDateAddedOnCopy()  : mixed
Sets the current date as the date added -> usually used on copy.
setDefaultsFromDca()  : mixed
Set initial $varData from dca.
setFieldsToReadOnly()  : mixed
combiner()  : mixed
Taken from \Contao\DataContainer.

Constants

AUTHOR_TYPE_MEMBER

public mixed AUTHOR_TYPE_MEMBER = 'member'

AUTHOR_TYPE_NONE

public mixed AUTHOR_TYPE_NONE = 'none'

AUTHOR_TYPE_SESSION

public mixed AUTHOR_TYPE_SESSION = 'session'

AUTHOR_TYPE_USER

public mixed AUTHOR_TYPE_USER = 'user'

PROPERTY_AUTHOR

public mixed PROPERTY_AUTHOR = 'author'

PROPERTY_AUTHOR_TYPE

public mixed PROPERTY_AUTHOR_TYPE = 'authorType'

PROPERTY_SESSION_ID

public mixed PROPERTY_SESSION_ID = 'sessionID'

Properties

$container

protected ContainerInterface $container

$framework

protected ContaoFrameworkInterface $framework

$connection

private Connection $connection

Methods

__construct()

public __construct(ContainerInterface $container, ContaoFrameworkInterface $framework, RoutingUtil $routingUtil, Connection $connection) : mixed
Parameters
$container : ContainerInterface
$framework : ContaoFrameworkInterface
$routingUtil : RoutingUtil
$connection : Connection

activateNotificationType()

public activateNotificationType(mixed $strGroup, mixed $strType, mixed $arrType) : mixed
Parameters
$strGroup : mixed
$strType : mixed
$arrType : mixed

addAliasToDca()

Adds an alias field to the dca and to the desired palettes.

public addAliasToDca(mixed $dca, mixed $generateAliasCallback, mixed $paletteField[, array<string|int, mixed> $palettes = ['default'] ]) : mixed
Parameters
$dca : mixed
$generateAliasCallback : mixed

mixed The callback to call for generating the alias

$paletteField : mixed

String The field after which to insert the alias field in the palettes

$palettes : array<string|int, mixed> = ['default']

The palettes in which to insert the field

addAuthorFieldAndCallback()

public addAuthorFieldAndCallback(string $table[, string $fieldPrefix = '' ]) : mixed

Use AuthorField::register() instead

Parameters
$table : string
$fieldPrefix : string = ''

addOverridableFields()

Adds an override selector to every field in $fields to the dca associated with $destinationTable.

public addOverridableFields(array<string|int, mixed> $fields, string $sourceTable, string $destinationTable[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$fields : array<string|int, mixed>
$sourceTable : string
$destinationTable : string
$options : array<string|int, mixed> = []

aliasExist()

Return if the current alias already exist in table.

public aliasExist(string $alias, int $id, string $table[, mixed $options = [] ]) : bool
Parameters
$alias : string
$id : int
$table : string
$options : mixed = []
Tags
throws
DBALException
Return values
bool

doGenerateDcOperationsButtons()

public doGenerateDcOperationsButtons(mixed $arrRow, mixed $strTable[, mixed $arrRootIds = [] ][, mixed $blnCircularReference = false ][, mixed $arrChildRecordIds = null ][, mixed $options = [] ]) : mixed
Parameters
$arrRow : mixed
$strTable : mixed
$arrRootIds : mixed = []
$blnCircularReference : mixed = false
$arrChildRecordIds : mixed = null
$options : mixed = []

flattenPaletteForSubEntities()

This function transforms an entity's palette (that can also contain sub palettes and concatenated type selectors) to a flatten palette where every field can be overridden.

public flattenPaletteForSubEntities(string $table, array<string|int, mixed> $overridableFields) : mixed

CAUTION: This function assumes that you have used addOverridableFields() for adding the fields that are overridable. The latter ones are $overridableFields

This function is useful if you want to adjust a palette for sub entities that can override properties of their ancestor(s). Use $this->getOverridableProperty() for computing the correct value respecting the entity hierarchy.

Parameters
$table : string
$overridableFields : array<string|int, mixed>

generateAlias()

Generate an alias with unique check.

public generateAlias(mixed $alias, int $id, string|null $table, string $title[, bool $keepUmlauts = true ][, mixed $options = [] ]) : string
Parameters
$alias : mixed

The current alias (if available)

$id : int

The entity's id

$table : string|null

The entity's table (pass a comma separated list if the validation should be expanded to multiple tables like tl_news AND tl_member. ATTENTION: the first table needs to be the one we're currently in). Pass null to skip unqiue check.

$title : string

The value to use as a base for the alias

$keepUmlauts : bool = true

Set to true if German umlauts should be kept

$options : mixed = []
Tags
throws
Exception
Return values
string

generateDcOperationsButtons()

public generateDcOperationsButtons(mixed $row, mixed $table[, mixed $rootIds = [] ][, mixed $options = [] ]) : mixed
Parameters
$row : mixed
$table : mixed
$rootIds : mixed = []
$options : mixed = []

generateSitemap()

public generateSitemap() : mixed

Get a contao backend modal archive edit link.

public getArchiveModalEditLink(string $module, int $id, string $table[, string|null $label = null ][, int $width = 1024 ]) : string

Use DcaUtil::getPopupWizardLink() instead

Parameters
$module : string

Name of the module

$id : int

Id of the entity

$table : string

The dataContainer table

$label : string|null = null

The label text

$width : int = 1024

The modal window width

Return values
string

The modal archive edit link

getAuthorNameByUserId()

public getAuthorNameByUserId(mixed $id) : mixed
Parameters
$id : mixed

getAuthorNameLinkByUserId()

public getAuthorNameLinkByUserId(mixed $id) : mixed
Parameters
$id : mixed

getConfigByArrayOrCallbackOrFunction()

Retrieves an array from a dca config (in most cases eval) in the following priorities:.

public getConfigByArrayOrCallbackOrFunction(array<string|int, mixed> $array, mixed $property[, array<string|int, mixed> $arguments = [] ]) : mixed|null
  1. The value associated to $array[$property]
  2. The value retrieved by $array[$property . '_callback'] which is a callback array like ['Class', 'method'] or ['service.id', 'method']
  3. The value retrieved by $array[$property . '_callback'] which is a function closure array like ['Class', 'method']
Parameters
$array : array<string|int, mixed>
$property : mixed
$arguments : array<string|int, mixed> = []
Return values
mixed|null

The value retrieved in the way mentioned above or null

getCurrentPaletteName()

Taken from \Contao\DataContainer.

public getCurrentPaletteName(string $table, int $id) : string|null
Parameters
$table : string
$id : int
Return values
string|null

getDataContainers()

Returns (nearly) all registered datacontainers as array.

public getDataContainers([array<string|int, mixed> $options = [] ]) : array<string|int, mixed>

Options:

  • bool onlyTableType: Return only table data containers
Parameters
$options : array<string|int, mixed> = []
Return values
array<string|int, mixed>

getDCTable()

Mostly used for Form::prepareSpecialValueForOutput().

public getDCTable(string $table, mixed $activeRecord) : DC_Table_Utils
Parameters
$table : string
$activeRecord : mixed
Return values
DC_Table_Utils

Get a contao backend modal edit link.

public getEditLink(string $module, int $id[, string|null $label = null ]) : string
Parameters
$module : string

Name of the module

$id : int

Id of the entity

$label : string|null = null

The label text

Return values
string

The edit link

getFieldLabel()

public getFieldLabel(string $table, string $field) : mixed
Parameters
$table : string
$field : string

getFields()

Returns a list of fields as an option array for dca fields.

public getFields(string $table[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>

Use Utils service instead

Possible options:

  • array inputTypes Restrict to certain input types
  • array evalConditions restrict to certain dca eval
  • bool localizeLabels
  • bool skipSorting
Parameters
$table : string
$options : array<string|int, mixed> = []
Tags
codeCoverageIgnore
Return values
array<string|int, mixed>

getLocalizedFieldName()

public getLocalizedFieldName(mixed $strField, mixed $strTable) : mixed
Parameters
$strField : mixed
$strTable : mixed

Get a contao backend modal edit link.

public getModalEditLink(string $module, int $id[, string|null $label = null ][, string $table = '' ][, int $width = 1024 ]) : string

Use DcaUtil::getPopupWizardLink() instead

Parameters
$module : string

Name of the module

$id : int

Id of the entity

$label : string|null = null

The label text

$table : string = ''

The dataContainer table

$width : int = 1024

The modal window width

Return values
string

The modal edit link

getNewNotificationTypeArray()

public getNewNotificationTypeArray([bool $includeNotificationCenterPlusTokens = false ]) : array<string|int, mixed>
Parameters
$includeNotificationCenterPlusTokens : bool = false
Return values
array<string|int, mixed>

getNewSortingPosition()

Returns the set of pid and sorting to be used in an sql update statement. Also updates the existing records according to the usage.

public getNewSortingPosition(string $table, int $id[, mixed $pid = null ][, mixed $insertAfterId = null ]) : array<string|int, mixed>

The method can be used in several ways:

  • Insert in an archive of a certain pid as first item: $pid must be set (0 is also ok), $insertAfterId needs to be null
  • Insert after a record of a certain id: $insertAfterId must be set, $pid can be set if necessary
Parameters
$table : string
$id : int
$pid : mixed = null
$insertAfterId : mixed = null
Tags
example

// insert a new record after another one with the ID 82

$news = new \Contao\NewsModel(); $news->pid = 3; $news->tstamp = time(); $news->title = 'Something'; $news->save(); $set = System::getContainer()->get('huh.utils.dca')->getNewSortingPosition( 'tl_news', $news->id, 3, 82 );

// store the returned set to the news record created above as usual

Hint: Mostly taken from DC_Table::getNewPosition(). Removed: handling if only a pid field is present, mode handling (since we don't have it in this context).

Return values
array<string|int, mixed>

getOverridableProperty()

Retrieves a property of given contao model instances by *ascending* priority, i.e. the last instance of $instances will have the highest priority.

public getOverridableProperty(string $property, array<string|int, mixed> $instances) : mixed

CAUTION: This function assumes that you have used addOverridableFields() in this class!! That means, that a value in a model instance is only used if it's either the first instance in $arrInstances or "overrideFieldname" is set to true in the instance.

Parameters
$property : string

The property name to retrieve

$instances : array<string|int, mixed>

An array of instances in ascending priority. Instances can be passed in the following form: ['tl_some_table', $instanceId] or $objInstance

Get a contao backend popup link.

public getPopupWizardLink(array<string|int, mixed> $parameter[, array<string|int, mixed> $options = [] ]) : string

Options:

  • attributes: (array) Link attributes as key value pairs. Will override title and style option. href and onclick are not allowed and will be removed from list.
  • title: (string) Overrride default link title
  • style: (string) Override default css style properties
  • onclick: (string) Override default onclick javascript code
  • icon: (string) Link icon to show as link text. Overrides default icon.
  • linkText: (string) A linkTitle to show as link text. Will be displayed after the link icon. Default empty.
  • url-only: (boolean) Return only url instead of a complete link element
Parameters
$parameter : array<string|int, mixed>

An array of parameter. Using string is deprecated and will be removed in a future version.

$options : array<string|int, mixed> = []
Return values
string

getRenderedDiff()

public getRenderedDiff(string $table, array<string|int, mixed> $source, array<string|int, mixed> $target[, array<string|int, mixed> $config = [] ]) : mixed
Parameters
$table : string
$source : array<string|int, mixed>
$target : array<string|int, mixed>
$config : array<string|int, mixed> = []

getSubPaletteFieldSelector()

Returns the selector of the sub palette a field is placed in. Currently doesn't support fields in multiple sub palettes.

public getSubPaletteFieldSelector(string $field, string $table) : string
Parameters
$field : string
$table : string
Return values
string

getTranslatedModuleNameByTable()

public getTranslatedModuleNameByTable(string $table) : mixed
Parameters
$table : string

isDcMultilingual()

public isDcMultilingual(string $table) : mixed
Parameters
$table : string

isDcMultilingual3()

public isDcMultilingual3() : mixed

isSubPaletteField()

Returns true if the field is in at least one sub palette.

public isSubPaletteField(string $field, string $table) : bool
Parameters
$field : string
$table : string
Return values
bool

loadDc()

Load a data container in a testable way.

public loadDc(string $table) : mixed
Parameters
$table : string

loadLanguageFile()

Load a language file in a testable way.

public loadLanguageFile(string $table) : mixed
Parameters
$table : string

modifyAuthorPaletteOnLoad()

public modifyAuthorPaletteOnLoad(DataContainer $dc) : mixed
Parameters
$dc : DataContainer

prepareRowEntryForList()

public prepareRowEntryForList(mixed $table, string $field, mixed $value) : mixed
Parameters
$table : mixed
$field : string
$value : mixed

setAuthorIDOnCreate()

public setAuthorIDOnCreate(string $table, int $id, array<string|int, mixed> $row, DataContainer $dc) : mixed
Parameters
$table : string
$id : int
$row : array<string|int, mixed>
$dc : DataContainer

setDateAdded()

Sets the current date as the date added -> usually used on submit.

public setDateAdded(DataContainer $dc) : mixed

Use DateAddedField instead

Parameters
$dc : DataContainer

setDateAddedOnCopy()

Sets the current date as the date added -> usually used on copy.

public setDateAddedOnCopy(mixed $insertId, DataContainer $dc) : mixed

Use DateAddedField instead

Parameters
$insertId : mixed
$dc : DataContainer

setDefaultsFromDca()

Set initial $varData from dca.

public setDefaultsFromDca(string $strTable[, mixed $varData = null ][, bool $includeSql = false ]) : mixed
Parameters
$strTable : string

Dca table name

$varData : mixed = null

Object or array

$includeSql : bool = false
Return values
mixed

Object or array with the default values

setFieldsToReadOnly()

public setFieldsToReadOnly(mixed &$dca[, array<string|int, mixed> $config = [] ]) : mixed
Parameters
$dca : mixed
$config : array<string|int, mixed> = []

combiner()

Taken from \Contao\DataContainer.

private combiner(mixed $names) : mixed
Parameters
$names : mixed

        
On this page

Search results