Skip to content
Last updated

WHMCS\CustomField

Class · extends AbstractModel

Custom Fields model class

Constants

NameDescription
TYPE_ADDON
TYPE_CLIENT
TYPE_PRODUCT
TYPE_SUPPORT

Methods

boot

public static function boot()

scopeClientFields

public function scopeClientFields(Builder $query)

Obtain all the client custom fields

Parameters

TypeNameDescription
Builder$query

Returns Builder

scopeProductFields

public function scopeProductFields(Builder $query, $productId)

Obtain all the product custom fields for a specific product.

Parameters

TypeNameDescription
Builder$query
int$productId

Returns Builder

scopeSupportFields

public function scopeSupportFields(Builder $query, $departmentId)

Obtain all the support custom fields for a specific support department.

Parameters

TypeNameDescription
Builder$query
int$departmentId

Returns Builder

scopeAddonFields

public function scopeAddonFields(Builder $query, $addonId)

Obtain all the addon custom fields for a specific addon id.

Parameters

TypeNameDescription
Builder$query
int$addonId

Returns Builder

product

public function product()

A custom field can belong to a single product

Returns HasOne\|Product

addon

public function addon()

A custom field can belong to a single product addon.

Returns HasOne\|Addon

getFieldNameAttribute

public function getFieldNameAttribute($fieldName)

Get the custom field's name - this will override the output from the db value if set in Lang.

Parameters

TypeNameDescription
string$fieldNameThe value from the database

Returns string

getDescriptionAttribute

public function getDescriptionAttribute($description)

Get the custom field's name - this will override the output from the db value if set in Lang.

Parameters

TypeNameDescription
string$descriptionThe value from the database

Returns string

customFieldValues

public function customFieldValues()

Returns HasMany\|CustomFieldValue

getFieldName

public static function getFieldName($fieldId, $fallback = '', $language = null)

Obtain the custom field name for the current language, passed language or fallback to the currently defined value for the product group.

Parameters

TypeNameDescription
int$fieldId
string$fallback
string$language

Returns string

getFriendlyDisplayFieldName

public function getFriendlyDisplayFieldName(): ?string

Attempt to retrieve an alternate field name that is embedded within this object’s fieldName

Returns string\|null

hasFriendlyDisplayFieldName

public function hasFriendlyDisplayFieldName(): bool

Determines if an alternate field name is embedded within this object’s fieldName, if dynamic translations are enabled

Returns bool

getFieldNameTranslation

public function getFieldNameTranslation(?string $language, bool $assumeEnabled = false): ?string

Attempt to retrieve a dynamic translation of this object's fieldName

Parameters

TypeNameDescription
null|string$language
bool$assumeEnabledAttempt translation despite dynamic translations possibly being disabled

Returns null\|string

getDescription

public static function getDescription($fieldId, $fallback = '', $language = null)

Obtain the custom field description for the current language, passed language or fallback to the currently defined value for the product group.

Parameters

TypeNameDescription
int$fieldId
string$fallback
string$language

Returns string

scopeRequired

public function scopeRequired(Builder $query): Builder

scopeOnOrderShow

public function scopeOnOrderShow(Builder $query): Builder

scopeOnOrderHide

public function scopeOnOrderHide(Builder $query): Builder

scopeAdminOnly

public function scopeAdminOnly(Builder $query): Builder

scopeNotAdminOnly

public function scopeNotAdminOnly(Builder $query): Builder

scopeShowOnOrderForm

public function scopeShowOnOrderForm(Builder $query): Builder

commonQueryBuilder

public static function commonQueryBuilder($type, $relid = 0, bool $onOrderOnly = false)

Initialize a query for custom fields that outlines common requirements and default behaviors.

Parameters

TypeNameDescription
string$typeType of custom field
int$relidOptionally limit fields to those associated with the $type's ID.
bool$onOrderOnlytrue=include on fields with "show on order" or "required" enabled. A "required" field is assumed to also be present in any context "show on order" enabled fields are. false=no additional criteria related to "show on order" or "required".

Returns Builder

getType

public function getType(): ?string

getOptions

public function getOptions(): array