Component ​
- Type
- Abstract Class
- Namespace
- craft\base
- Inherits
- craft\base\Component » craft\base\Model » yii\base\Model » yii\base\Component » yii\base\BaseObject
- Implements
- ArrayAccess, IteratorAggregate, craft\base\ComponentInterface, craft\base\ModelInterface, yii\base\Arrayable, yii\base\Configurable, yii\base\StaticInstanceInterface
- Uses traits
- craft\base\ClonefixTrait, yii\base\ArrayableTrait, yii\base\StaticInstanceTrait
- Extended by
- craft\assetpreviews\Image, craft\assetpreviews\Pdf, craft\assetpreviews\Text, craft\assetpreviews\Video, craft\base\AssetPreviewHandler, craft\base\ConfigurableComponent, craft\base\Element, craft\base\ElementAction, craft\base\ElementExporter, craft\base\Field, craft\base\Fs, craft\base\SavableComponent, craft\base\Utility, craft\base\Widget, craft\base\conditions\BaseCondition, craft\base\conditions\BaseConditionRule, craft\base\conditions\BaseDateRangeConditionRule, craft\base\conditions\BaseElementSelectConditionRule, craft\base\conditions\BaseLightswitchConditionRule, craft\base\conditions\BaseMultiSelectConditionRule, craft\base\conditions\BaseNumberConditionRule, craft\base\conditions\BaseSelectConditionRule, craft\base\conditions\BaseTextConditionRule, craft\elements\Address, craft\elements\Asset, craft\elements\Category, craft\elements\Entry, craft\elements\GlobalSet, craft\elements\MatrixBlock, craft\elements\Tag, craft\elements\User, craft\elements\actions\CopyReferenceTag, craft\elements\actions\CopyUrl, craft\elements\actions\Delete, craft\elements\actions\DeleteAssets, craft\elements\actions\DeleteForSite, craft\elements\actions\DeleteUsers, craft\elements\actions\DownloadAssetFile, craft\elements\actions\Duplicate, craft\elements\actions\Edit, craft\elements\actions\EditImage, craft\elements\actions\MoveAssets, craft\elements\actions\NewChild, craft\elements\actions\NewSiblingAfter, craft\elements\actions\NewSiblingBefore, craft\elements\actions\PreviewAsset, craft\elements\actions\RenameFile, craft\elements\actions\ReplaceFile, craft\elements\actions\Restore, craft\elements\actions\SetStatus, craft\elements\actions\SuspendUsers, craft\elements\actions\UnsuspendUsers, craft\elements\actions\View, craft\elements\conditions\DateCreatedConditionRule, craft\elements\conditions\DateUpdatedConditionRule, craft\elements\conditions\ElementCondition, craft\elements\conditions\HasDescendantsRule, craft\elements\conditions\HasUrlConditionRule, craft\elements\conditions\IdConditionRule, craft\elements\conditions\LanguageConditionRule, craft\elements\conditions\LevelConditionRule, craft\elements\conditions\RelatedToConditionRule, craft\elements\conditions\SiteConditionRule, craft\elements\conditions\SiteGroupConditionRule, craft\elements\conditions\SlugConditionRule, craft\elements\conditions\StatusConditionRule, craft\elements\conditions\TitleConditionRule, craft\elements\conditions\UriConditionRule, craft\elements\conditions\addresses\AddressCondition, craft\elements\conditions\addresses\AdministrativeAreaConditionRule, craft\elements\conditions\addresses\CountryConditionRule, craft\elements\conditions\assets\AssetCondition, craft\elements\conditions\assets\DateModifiedConditionRule, craft\elements\conditions\assets\FileSizeConditionRule, craft\elements\conditions\assets\FileTypeConditionRule, craft\elements\conditions\assets\FilenameConditionRule, craft\elements\conditions\assets\HasAltConditionRule, craft\elements\conditions\assets\HeightConditionRule, craft\elements\conditions\assets\SavableConditionRule, craft\elements\conditions\assets\UploaderConditionRule, craft\elements\conditions\assets\ViewableConditionRule, craft\elements\conditions\assets\VolumeConditionRule, craft\elements\conditions\assets\WidthConditionRule, craft\elements\conditions\categories\CategoryCondition, craft\elements\conditions\categories\GroupConditionRule, craft\elements\conditions\entries\AuthorConditionRule, craft\elements\conditions\entries\AuthorGroupConditionRule, craft\elements\conditions\entries\EntryCondition, craft\elements\conditions\entries\ExpiryDateConditionRule, craft\elements\conditions\entries\PostDateConditionRule, craft\elements\conditions\entries\SavableConditionRule, craft\elements\conditions\entries\SectionConditionRule, craft\elements\conditions\entries\TypeConditionRule, craft\elements\conditions\entries\ViewableConditionRule, craft\elements\conditions\tags\GroupConditionRule, craft\elements\conditions\tags\TagCondition, craft\elements\conditions\users\AdminConditionRule, craft\elements\conditions\users\CredentialedConditionRule, craft\elements\conditions\users\EmailConditionRule, craft\elements\conditions\users\FirstNameConditionRule, craft\elements\conditions\users\GroupConditionRule, craft\elements\conditions\users\LastLoginDateConditionRule, craft\elements\conditions\users\LastNameConditionRule, craft\elements\conditions\users\UserCondition, craft\elements\conditions\users\UsernameConditionRule, craft\elements\exporters\Expanded, craft\elements\exporters\Raw, craft\fields\Assets, craft\fields\BaseOptionsField, craft\fields\BaseRelationField, craft\fields\Categories, craft\fields\Checkboxes, craft\fields\Color, craft\fields\Country, craft\fields\Date, craft\fields\Dropdown, craft\fields\Email, craft\fields\Entries, craft\fields\Lightswitch, craft\fields\Matrix, craft\fields\MissingField, craft\fields\Money, craft\fields\MultiSelect, craft\fields\Number, craft\fields\PlainText, craft\fields\RadioButtons, craft\fields\Table, craft\fields\Tags, craft\fields\Time, craft\fields\Url, craft\fields\Users, craft\fields\conditions\CountryFieldConditionRule, craft\fields\conditions\DateFieldConditionRule, craft\fields\conditions\EmptyFieldConditionRule, craft\fields\conditions\LightswitchFieldConditionRule, craft\fields\conditions\NumberFieldConditionRule, craft\fields\conditions\OptionsFieldConditionRule, craft\fields\conditions\RelationalFieldConditionRule, craft\fields\conditions\TextFieldConditionRule, craft\fs\Local, craft\fs\MissingFs, craft\fs\Temp, craft\gql\ArgumentManager, craft\gql\ElementQueryConditionBuilder, craft\gql\TypeManager, craft\gql\base\ElementMutationResolver, craft\gql\base\MutationResolver, craft\gql\resolvers\mutations\Asset, craft\gql\resolvers\mutations\Category, craft\gql\resolvers\mutations\Entry, craft\gql\resolvers\mutations\GlobalSet, craft\gql\resolvers\mutations\Tag, craft\imagetransforms\FallbackTransformer, craft\imagetransforms\ImageTransformer, craft\mail\transportadapters\BaseTransportAdapter, craft\mail\transportadapters\Gmail, craft\mail\transportadapters\Sendmail, craft\mail\transportadapters\Smtp, craft\test\mockclasses\components\ComponentExample, craft\test\mockclasses\components\DependencyHeavyComponentExample, craft\test\mockclasses\components\EventTriggeringComponent, craft\test\mockclasses\components\ExtendedComponentExample, craft\test\mockclasses\elements\ExampleElement, craft\utilities\AssetIndexes, craft\utilities\ClearCaches, craft\utilities\DbBackup, craft\utilities\DeprecationErrors, craft\utilities\FindAndReplace, craft\utilities\Migrations, craft\utilities\PhpInfo, craft\utilities\ProjectConfig, craft\utilities\QueueManager, craft\utilities\SystemMessages, craft\utilities\SystemReport, craft\utilities\Updates, craft\utilities\Upgrade, craft\widgets\CraftSupport, craft\widgets\Feed, craft\widgets\MissingWidget, craft\widgets\MyDrafts, craft\widgets\NewUsers, craft\widgets\QuickPost, craft\widgets\RecentEntries, craft\widgets\Updates
- Since
- 3.0.0
Component is the base class for classes representing Craft components in terms of objects.
Public Properties ​
Property | Description |
---|---|
activeValidators | yii\validators\Validator – The validators applicable to the current scenario. |
attributes | array – Attribute values (name => value). |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
errors | array – Errors for all attributes or the specified attribute. |
firstErrors | array – The first errors. |
iterator | ArrayIterator – An iterator for traversing the items in the list. |
scenario | string – The scenario that this model is in. |
validators | ArrayObject, yii\validators\Validator – All the validators declared in the model. |
Public Methods ​
Method | Description |
---|---|
__call() | Calls the named method which is not a class method. |
__clone() | This method is called after the object is created by cloning an existing one. |
__construct() | |
__get() | Returns the value of a component property. |
__isset() | Checks if a property is set, i.e. defined and not null. |
__set() | Sets the value of a component property. |
__unset() | Sets a component property to be null. |
activeAttributes() | Returns the attribute names that are subject to validation in the current scenario. |
addError() | Adds a new error to the specified attribute. |
addErrors() | Adds a list of errors. |
addModelErrors() | Adds errors from another model, with a given attribute name prefix. |
afterValidate() | This method is invoked after validation ends. |
attachBehavior() | Attaches a behavior to this component. |
attachBehaviors() | Attaches a list of behaviors to the component. |
attributeHints() | Returns the attribute hints. |
attributeLabels() | Returns the attribute labels. |
attributes() | Returns the list of attribute names. |
beforeValidate() | This method is invoked before validation starts. |
behaviors() | Returns a list of behaviors that this component should behave as. |
canGetProperty() | Returns a value indicating whether a property can be read. |
canSetProperty() | Returns a value indicating whether a property can be set. |
className() | Returns the fully qualified name of this class. |
clearErrors() | Removes errors for all attributes or a single attribute. |
createValidators() | Creates validator objects based on the validation rules specified in rules(). |
datetimeAttributes() | Returns the names of any attributes that should hold DateTime values. |
detachBehavior() | Detaches a behavior from the component. |
detachBehaviors() | Detaches all behaviors from the component. |
displayName() | Returns the display name of this class. |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. |
extraFields() | Returns the list of fields that can be expanded further and returned by toArray(). |
fields() | Returns the list of fields that should be returned by default by toArray() when no specific fields are specified. |
formName() | Returns the form name that this model class should use. |
generateAttributeLabel() | Generates a user friendly attribute label based on the give attribute name. |
getActiveValidators() | Returns the validators applicable to the current scenario. |
getAttributeHint() | Returns the text hint for the specified attribute. |
getAttributeLabel() | Returns the text label for the specified attribute. |
getAttributes() | Returns attribute values. |
getBehavior() | Returns the named behavior object. |
getBehaviors() | Returns all behaviors attached to this component. |
getErrorSummary() | Returns the errors for all attributes as a one-dimensional array. |
getErrors() | Returns the errors for all attributes or a single attribute. |
getFirstError() | Returns the first error of the specified attribute. |
getFirstErrors() | Returns the first error of every attribute in the model. |
getIterator() | Returns an iterator for traversing the attributes in the model. |
getScenario() | Returns the scenario that this model is used in. |
getValidators() | Returns all the validators declared in rules(). |
hasErrors() | Returns a value indicating whether there is any validation error. |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() | Returns a value indicating whether a method is defined. |
hasProperty() | Returns a value indicating whether a property is defined for this component. |
init() | Initializes the object. |
instance() | Returns static class instance, which can be used to obtain meta information. |
isAttributeActive() | Returns a value indicating whether the attribute is active in the current scenario. |
isAttributeRequired() | Returns a value indicating whether the attribute is required. |
isAttributeSafe() | Returns a value indicating whether the attribute is safe for massive assignments. |
isSelectable() | Returns whether the component should be selectable in component Type selects. |
load() | Populates the model with input data. |
loadMultiple() | Populates a set of models with the data from end user. |
off() | Detaches an existing event handler from this component. |
offsetExists() | Returns whether there is an element at the specified offset. |
offsetGet() | Returns the element at the specified offset. |
offsetSet() | Sets the element at the specified offset. |
offsetUnset() | Sets the element value at the specified offset to null. |
on() | Attaches an event handler to an event. |
onUnsafeAttribute() | This method is invoked when an unsafe attribute is being massively assigned. |
rules() | Returns the validation rules for attributes. |
safeAttributes() | Returns the attribute names that are safe to be massively assigned in the current scenario. |
scenarios() | Returns a list of scenarios and the corresponding active attributes. |
setAttributes() | Sets the attribute values in a massive way. |
setScenario() | Sets the scenario for the model. |
toArray() | Converts the model into an array. |
trigger() | Triggers an event. |
validate() | Performs the data validation. |
validateMultiple() | Validates multiple models. |
displayName()
​
Returns the display name of this class.
Returns ​
string – The display name of this class.
isSelectable()
​
- Since
- 3.5.0
Returns whether the component should be selectable in component Type selects.
Returns ​
boolean – Whether the component should be selectable in component Type selects.
Protected Methods ​
Method | Description |
---|---|
defineBehaviors() | Returns the behaviors to attach to this class. |
defineRules() | Returns the validation rules for attributes. |
extractFieldsFor() | Extract nested fields from a fields collection for a given root field Nested fields are separated with dots (.). e.g: "item.id" The previous example would extract "id". |
extractRootFields() | Extracts the root field names from nested fields. |
resolveFields() | Determines which fields can be returned by toArray(). |
Constants ​
Constant | Description |
---|---|
SCENARIO_DEFAULT | The name of the default scenario. |