CRUDlex\EntityDefinition

class EntityDefinition

The class for defining a single entity.

property table

protected

The table where the data is stored.

property fields

protected

Holds all fields in the same structure as in the CRUD YAML file.

property label

protected

The label for the entity.

property localeLabels

protected

The labels of the entity in the locales.

property children

protected

An array with the children referencing the entity. All entries are arrays with three referencing elements: table, fieldName, entity

property standardFieldLabels

protected

Labels for the fields “id”, “created_at” and “updated_at”.

property listFields

protected

An array containing the fields which should appear in the list view of the entity.

property childrenLabelFields

protected

The fields used to display the children on the details page of an entity. The keys are the entity names as in the CRUD YAML and the values are the field names.

property deleteCascade

protected

Whether to delete its children when an instance is deleted.

property pageSize

protected

The amount of items to display per page on the listview.

property filter

protected

The fields offering to be filtered.

property serviceProvider

protected

Holds the {@see ServiceProvider}.

property locale

protected

Holds the locale.

property initialSortField

protected

Holds the initial sort field.

property initialSortAscending

protected

Holds the initial sort order.

getFilteredFieldNames($exclude)

Gets the field names exluding the given ones.

Parameters:
  • $exclude (string[]) – the field names to exclude
Returns:

array all field names excluding the given ones

checkFieldNames($reference, $fieldNames)

Checks whether the given field names are declared and existing.

Parameters:
  • $reference (string) – a hint towards the source of an invalid field name
  • $fieldNames (array) – the field names to check
__construct($table, $fields, $label, $localeLabels, $standardFieldLabels, ServiceProvider $serviceProvider)

Constructor.

Parameters:
  • $table (string) – the table of the entity
  • $fields (array) – the field structure just like the CRUD YAML
  • $label (string) – the label of the entity
  • $localeLabels (array) – the labels of the entity in the locales
  • $standardFieldLabels (array) – labels for the fields “id”, “created_at” and “updated_at”
  • $serviceProvider (ServiceProvider) – The current service provider
getFieldNames($includeMany = false)

Gets all field names, including the implicit ones like “id” or “created_at”.

Parameters:
  • $includeMany (boolean) – whether to include the many fields as well
Returns:

string[] the field names

setListFields($listFields)

Sets the field names to be used in the listview.

Parameters:
  • $listFields (array) – the field names to be used in the listview
getListFields()

Gets the field names to be used in the listview. If they were not specified, all public field names are returned.

Returns:array the field names to be used in the listview
getChildrenLabelFields()

Gets the fields used to display the children on the details page of an entity. The keys are the entity names as in the CRUD YAML and the values are the field names.

Returns:array the fields used to display the children on the details page
setChildrenLabelFields($childrenLabelFields)

Sets the fields used to display the children on the details page of an entity. The keys are the entity names as in the CRUD YAML and the values are the field names.

Parameters:
  • $childrenLabelFields (array) – the fields used to display the children on the details page
isDeleteCascade()

Gets whether to delete its children when an instance is deleted.

Returns:boolean true if so
setDeleteCascade($deleteCascade)

Sets whether to delete its children when an instance is deleted.

Parameters:
  • $deleteCascade (boolean) – whether to delete its children when an instance is deleted
getPageSize()

Gets the amount of items to display per page on the listview.

Returns:integer the amount of items to display per page on the listview
setPageSize($pageSize)

Sets the amount of items to display per page on the listview.

Parameters:
  • $pageSize (integer) – the amount of items to display per page on the listview
getFilter()

Gets the fields offering a filter.

Returns:array the fields to filter
setFilter($filter)

Sets the fields offering a filter.

Parameters:
  • $filter (array) – the fields to filter
getServiceProvider()

Gets the service provider.

Returns:ServiceProvider the service provider
setServiceProvider(ServiceProvider $serviceProvider)

Sets the service provider.

Parameters:
getPublicFieldNames()

Gets the public field names. The internal fields “version” and “deleted_at” are filtered.

Returns:array the public field names
getEditableFieldNames()

Gets the field names which are editable. Not editable are fields like the id or the created_at.

Returns:array the editable field names
getReadOnlyFields()

Gets the read only field names like the id or the created_at.

Returns:string[] the read only field names
getType($fieldName)

Gets the type of a field.

Parameters:
  • $fieldName (string) – the field name
Returns:

string the type or null on invalid field name

setType($fieldName, $value)

Sets the type of a field.

Parameters:
  • $fieldName (string) – the field name
  • $value (string) – the new field type
getFieldLabel($fieldName)

Gets the label of a field.

Parameters:
  • $fieldName (string) – the field name
Returns:

string the label of the field or the field name if no label is set in the CRUD YAML

setFieldLabel($fieldName, $value)

Gets the label of a field.

Parameters:
  • $fieldName (string) – the field name
  • $value (string) – the new label of the field
getTable()

Gets the table where the data is stored.

Returns:string the table where the data is stored
setTable($table)

Sets the table where the data is stored.

Parameters:
  • $table (string) – the new table where the data is stored
getLabel()

Gets the label for the entity.

Returns:string the label for the entity
setLabel($label)

Sets the label for the entity.

Parameters:
  • $label (string) – the new label for the entity
addChild($table, $fieldName, $entity)

Adds a child to this definition in case the other definition has a reference to this one.

Parameters:
  • $table (string) – the table of the referencing definition
  • $fieldName (string) – the field name of the referencing definition
  • $entity (string) – the entity of the referencing definition
getChildren()

Gets the referencing children to this definition.

Returns:array an array with the children referencing the entity. All entries are arrays with three referencing elements: table, fieldName, entity
setLocale($locale)

Sets the locale to be used.

Parameters:
  • $locale (string) – the locale to be used.
getLocale()

Gets the locale to be used.

Returns:null|string the locale to be used.
setInitialSortField($initialSortField)

Sets the initial sort field.

Parameters:
  • $initialSortField (string) – the new initial sort field
getInitialSortField()

Gets the initial sort field.

Returns:string the initial sort field
setInitialSortAscending($initialSortAscending)

Sets the initial sort order.

Parameters:
  • $initialSortAscending (boolean) – the initial sort order, true if ascending
isInitialSortAscending()

Gets the initial sort order.

Returns:boolean the initial sort order, true if ascending
getSubTypeField($fieldName, $subType, $key)

Gets a sub field of an field.

Parameters:
  • $fieldName (string) – the field name of the sub type
  • $subType (string) – the sub type like “reference” or “many”
  • $key (string) – the key of the value
Returns:

string the value of the sub field

getField($name, $key, $default = null)

Gets the value of a field key.

Parameters:
  • $name (string) – the name of the field
  • $key (string) – the value of the key
  • $default (mixed) – the default value to return if nothing is found
Returns:

mixed the value of the field key or null if not existing

setField($name, $key, $value)

Sets the value of a field key. If the field or the key in the field don’t exist, they get created.

Parameters:
  • $name (string) – the name of the field
  • $key (string) – the value of the key
  • $value (mixed) – the new value