OrderElementTrait ​
- Type
- Trait
- Namespace
- craft\commerce\elements\traits
- Implemented by
- craft\commerce\elements\Order
Public Methods ​
Method | Description |
---|---|
createCondition() | Returns an element condition for the element type. |
find() | Creates an \ElementQueryInterface instance for query purpose. |
getFieldLayout() | Returns the field layout used by this element. |
getSearchKeywords() | Returns the search keywords for a given search attribute. |
hasContent() | Returns whether elements of this type will be storing any data in the content table (titles or custom fields). |
prepElementQueryForTableAttribute() | Prepares an element query for an element index that includes a given table attribute. |
createCondition()
​
Returns an element condition for the element type.
Returns ​
craft\commerce\elements\conditions\orders\OrderCondition
find()
​
Creates an \ElementQueryInterface
instance for query purpose.
The returned \ElementQueryInterface
instance can be further customized by calling methods defined in \ElementQueryInterface
before one()
or all()
is called to return populated \ElementInterface
instances. For example,
// Find the entry whose ID is 5
$entry = Entry::find()->id(5)->one();
// Find all assets and order them by their filename:
$assets = Asset::find()
->orderBy('filename')
->all();
If you want to define custom criteria parameters for your elements, you can do so by overriding this method and returning a custom query class. For example,
class Product extends Element
{
public static function find(): ElementQueryInterface
{
// use ProductQuery instead of the default ElementQuery
return new ProductQuery(get_called_class());
}
}
You can also set default criteria parameters on the ElementQuery if you don’t have a need for a custom query class. For example,
class Customer extends ActiveRecord
{
public static function find(): ElementQueryInterface
{
return parent::find()->limit(50);
}
}
Returns ​
craft\commerce\elements\db\OrderQuery – The newly created \OrderQuery
instance.
getFieldLayout()
​
Returns the field layout used by this element.
Returns ​
craft\models\FieldLayout, null
getSearchKeywords()
​
Returns the search keywords for a given search attribute.
Arguments ​
$attribute
(string)
Returns ​
hasContent()
​
Returns whether elements of this type will be storing any data in the content
table (titles or custom fields).
Returns ​
boolean – Whether elements of this type will be storing any data in the content
table.
prepElementQueryForTableAttribute()
​
Prepares an element query for an element index that includes a given table attribute.
Arguments ​
$elementQuery
(craft\elements\db\ElementQueryInterface)$attribute
(string)
Protected Methods ​
Method | Description |
---|---|
defineActions() | Defines the available element actions for a given source. |
defineDefaultTableAttributes() | Returns the list of table attribute keys that should be shown by default. |
defineExporters() | Defines the available element exporters for a given source. |
defineSearchableAttributes() | Defines which element attributes should be searchable. |
defineSortOptions() | Returns the sort options for the element type. |
defineSources() | Defines the sources that elements of this type may belong to. |
defineTableAttributes() | Defines all of the available columns that can be shown in table views. |
htmlAttributes() | Returns any attributes that should be included in the element’s DOM representation in the control panel. |
tableAttributeHtml() | Returns the HTML that should be shown for a given attribute in Table View. |
defineActions()
​
Defines the available element actions for a given source.
Arguments ​
$source
(string) – The selected source’s key, if any.
Returns ​
array – The available element actions.
defineDefaultTableAttributes()
​
Returns the list of table attribute keys that should be shown by default.
Arguments ​
$source
(string) – The selected source’s key
Returns ​
string[] – The table attributes.
defineExporters()
​
Defines the available element exporters for a given source.
Arguments ​
$source
(string) – The selected source’s key
Returns ​
array – The available element exporters
defineSearchableAttributes()
​
Defines which element attributes should be searchable.
Returns ​
string[] – The element attributes that should be searchable
defineSortOptions()
​
Returns the sort options for the element type.
Returns ​
array – The attributes that elements can be sorted by
defineSources()
​
Defines the sources that elements of this type may belong to.
Arguments ​
$context
(string) – The context ('index', 'modal', 'field', or 'settings').
Returns ​
array – The sources.
Throws ​
defineTableAttributes()
​
Defines all of the available columns that can be shown in table views.
Returns ​
array – The table attributes.
htmlAttributes()
​
Returns any attributes that should be included in the element’s DOM representation in the control panel.
Arguments ​
$context
(string) – The context that the element is being rendered in ('index', 'modal', 'field', or 'settings'.)
Returns ​
tableAttributeHtml()
​
Returns the HTML that should be shown for a given attribute in Table View.
This method can be used to completely customize what actually shows up within the table’s body for a given attribute, rather than simply showing the attribute’s raw value.
For example, if your elements have an email
attribute that you want to wrap in a mailto:
link, your tableAttributeHtml()
method could do this:
switch ($attribute) {
case 'email':
return $this->email ? Html::mailto(Html::encode($this->email)) : '';
// ...
}
return parent::tableAttributeHtml($attribute);
WARNING
All untrusted text should be passed through Html::encode()
to prevent XSS attacks.
By default the following will be returned:
- If the attribute name is
link
oruri
, it will be linked to the front-end URL. - If the attribute is a custom field handle, it will pass the responsibility off to the field type.
- If the attribute value is a DateTime object, the date will be formatted with a localized date format.
- For anything else, it will output the attribute value as a string.
Arguments ​
$attribute
(string) – The attribute name.
Returns ​
string – The HTML that should be shown for a given attribute in Table View.