TagModel

Packagecraft.app.models
NamespaceCraft
Inheritanceclass TagModel » BaseElementModel » BaseModel » \CModel » \CComponent
Implements\ArrayAccess, \Traversable, \IteratorAggregate
Since1.1
Source Codecraft/app/models/TagModel.php

Tag model class.

Public Properties #

PropertyTypeDescriptionDefined By
allErrorsarrayReturns all errors in a single, flattened list, devoid of attribute names.BaseModel
ancestorsElementCriteriaModelReturns the element's ancestors.BaseElementModel
attributeConfigsarrayReturns this model's normalized attribute configs.BaseModel
attributesarrayReturns an array of attribute values.BaseModel
childrenElementCriteriaModelReturns the element's children.BaseElementModel
classHandlestringGet the class name, sans namespace and suffix.BaseModel
contentContentModelReturns the content for the element.BaseElementModel
contentFromPostarrayReturns the raw content from the post data, before it was passed through prepValueFromPost().BaseElementModel
contentPostLocationstring / nullReturns the location in POST that the content was pulled from.BaseElementModel
contentTablestringReturns the name of the table this element's content is stored in.BaseElementModel
cpEditUrlstring / falseReturns the element's CP edit URL.BaseElementModel
descendantsElementCriteriaModelReturns the element's descendants.BaseElementModel
elementTypestringReturns the type of element this is.BaseElementModel
errorsarrayReturns the errors for all attribute or a single attribute.\CModel
extraAttributeNamesarrayReturns a list of the names of the extra attributes that have been saved on this model, if it's not strict.BaseModel
fieldColumnPrefixstringReturns the field column prefix this element's content uses.BaseElementModel
fieldContextstringReturns the field context this element's content uses.BaseElementModel
fieldLayoutFieldLayoutModel / nullReturns the field layout used by this element.TagModel
groupTagGroupModel / nullReturns the tag's group.TagModel
hasFreshContentboolReturns whether the element’s content is "fresh" (unsaved and without validation errors).BaseElementModel
iterator\CMapIteratorReturns an iterator for traversing the attributes in the model.\CModel
localesarrayReturns the locale IDs this element is available in.BaseElementModel
namestringReturns the tag's title.TagModel
nextElementCriteriaModel / nullReturns the next element relative to this one, from a given set of criteria.BaseElementModel
nextSiblingBaseElementModel / nullReturns the element's next sibling.BaseElementModel
parentBaseElementModel / nullGet the element's parent.BaseElementModel
parentsElementCriteriaModelReturns a new ElementCriteriaModel prepped to return this element's same-type parents.BaseElementModel
prevElementCriteriaModel / nullReturns the previous element relative to this one, from a given set of criteria.BaseElementModel
prevSiblingBaseElementModel / nullReturns the element's previous sibling.BaseElementModel
rawContentmixedReturns the raw content saved on this entity.BaseElementModel
refstring / nullReturns the reference string to this element.BaseElementModel
safeAttributeNamesarrayReturns the attribute names that are safe to be massively assigned.\CModel
scenariostringReturns the scenario that this model is used in.\CModel
setTagGroupModel / nullReturns the tag's group.TagModel
siblingsElementCriteriaModelReturns all of the element's siblings.BaseElementModel
statusstring / nullReturns the element's status.BaseElementModel
thumbUrlstring / nullReturns the URL to the element's thumbnail, if there is one.BaseElementModel
titlestringReturns the element's title.BaseElementModel
totalDescendantsboolReturns the total number of descendants that the element has.BaseElementModel
urlstringReturns the element's full URL.BaseElementModel
urlFormatstring / nullReturns the URL format used to generate this element's URL.BaseElementModel
validatorList\CListReturns all the validators declared in the model.\CModel
validatorsarrayReturns the validators applicable to the current scenario.\CModel

Protected Properties #

PropertyTypeDescriptionDefined By
classSuffixstringBaseModel
strictAttributesboolWhether this model should be strict about only allowing values to be set on defined attributesBaseModel

Public Methods #

MethodDescriptionDefined By
__call()Magic __call() method, used for chain-setting attribute values.BaseModel
__construct()ConstructorBaseModel
__get()GetterBaseElementModel
__isset()Treats custom fields as properties.BaseElementModel
__set()PHP setter magic method.BaseModel
__toString()Use the tag title as its string representation.TagModel
__unset()Sets a component property to be null.\CComponent
addError()Adds a new error to the specified attribute.\CModel
addErrors()Adds a list of errors.\CModel
asa()Returns the named behavior object.\CComponent
attachBehavior()Attaches a behavior to this component.\CComponent
attachBehaviors()Attaches a list of behaviors to the component.\CComponent
attachEventHandler()Attaches an event handler to an event.\CComponent
attributeLabels()Returns the attribute labels.BaseModel
attributeNames()Returns the list of this model's attribute names.BaseModel
behaviors()Returns a list of behaviors that this model should behave as.\CModel
canGetProperty()Determines whether a property can be read.\CComponent
canSetProperty()Determines whether a property can be set.\CComponent
clearErrors()Removes errors for all attributes or a single attribute.\CModel
copy()Returns a copy of this model.BaseModel
createValidators()Creates validator objects based on the specification in rules.\CModel
detachBehavior()Detaches a behavior from the component.\CComponent
detachBehaviors()Detaches all behaviors from the component.\CComponent
detachEventHandler()Detaches an existing event handler.\CComponent
disableBehavior()Disables an attached behavior.\CComponent
disableBehaviors()Disables all behaviors attached to this component.\CComponent
enableBehavior()Enables an attached behavior.\CComponent
enableBehaviors()Enables all behaviors attached to this component.\CComponent
evaluateExpression()Evaluates a PHP expression or callback under the context of this component.\CComponent
generateAttributeLabel()Generates a user friendly attribute label. This is done by replacing underscores or dashes with blanks and changing the first letter of each word to upper case. For example, 'department_name' or 'DepartmentName' becomes 'Department Name'.BaseModel
getAllErrors()Returns all errors in a single, flattened list, devoid of attribute names.BaseModel
getAncestors()Returns the element's ancestors.BaseElementModel
getAttribute()Gets an attribute’s value.BaseElementModel
getAttributeConfigs()Returns this model's normalized attribute configs.BaseModel
getAttributeLabel()Returns the text label for the specified attribute.\CModel
getAttributes()Returns an array of attribute values.BaseModel
getChildren()Returns the element's children.BaseElementModel
getClassHandle()Get the class name, sans namespace and suffix.BaseModel
getContent()Returns the content for the element.BaseElementModel
getContentFromPost()Returns the raw content from the post data, before it was passed through prepValueFromPost().BaseElementModel
getContentPostLocation()Returns the location in POST that the content was pulled from.BaseElementModel
getContentTable()Returns the name of the table this element's content is stored in.BaseElementModel
getCpEditUrl()Returns the element's CP edit URL.BaseElementModel
getDescendants()Returns the element's descendants.BaseElementModel
getEagerLoadedElements()Returns some eager-loaded elements on a given handle.BaseElementModel
getElementType()Returns the type of element this is.BaseElementModel
getError()Returns the first error of the specified attribute.\CModel
getErrors()Returns the errors for all attribute or a single attribute.\CModel
getEventHandlers()Returns the list of attached event handlers for an event.\CComponent
getExtraAttributeNames()Returns a list of the names of the extra attributes that have been saved on this model, if it's not strict.BaseModel
getFieldColumnPrefix()Returns the field column prefix this element's content uses.BaseElementModel
getFieldContext()Returns the field context this element's content uses.BaseElementModel
getFieldLayout()Returns the field layout used by this element.TagModel
getFieldValue()Returns the prepped content for a given field.BaseElementModel
getGroup()Returns the tag's group.TagModel
getHasFreshContent()Returns whether the element’s content is "fresh" (unsaved and without validation errors).BaseElementModel
getIterator()Returns an iterator for traversing the attributes in the model.\CModel
getLocales()Returns the locale IDs this element is available in.BaseElementModel
getName()Returns the tag's title.TagModel
getNext()Returns the next element relative to this one, from a given set of criteria.BaseElementModel
getNextSibling()Returns the element's next sibling.BaseElementModel
getParent()Get the element's parent.BaseElementModel
getParents()Returns a new ElementCriteriaModel prepped to return this element's same-type parents.BaseElementModel
getPrev()Returns the previous element relative to this one, from a given set of criteria.BaseElementModel
getPrevSibling()Returns the element's previous sibling.BaseElementModel
getRawContent()Returns the raw content saved on this entity.BaseElementModel
getRef()Returns the reference string to this element.BaseElementModel
getSafeAttributeNames()Returns the attribute names that are safe to be massively assigned.\CModel
getScenario()Returns the scenario that this model is used in.\CModel
getSet()Returns the tag's group.TagModel
getSiblings()Returns all of the element's siblings.BaseElementModel
getStatus()Returns the element's status.BaseElementModel
getThumbUrl()Returns the URL to the element's thumbnail, if there is one.BaseElementModel
getTitle()Returns the element's title.BaseElementModel
getTotalDescendants()Returns the total number of descendants that the element has.BaseElementModel
getUrl()Returns the element's full URL.BaseElementModel
getUrlFormat()Returns the URL format used to generate this element's URL.BaseElementModel
getValidatorList()Returns all the validators declared in the model.\CModel
getValidators()Returns the validators applicable to the current scenario.\CModel
hasDescendants()Returns whether the element has descendants.BaseElementModel
hasEagerLoadedElements()Returns whether elements have been eager-loaded with a given handle.BaseElementModel
hasErrors()Returns a value indicating whether there is any validation error.\CModel
hasEvent()Determines whether an event is defined.\CComponent
hasEventHandler()Checks whether the named event has attached handlers.\CComponent
hasProperty()Determines whether a property is defined.\CComponent
isAncestorOf()Returns whether this element is an ancestor of another one.BaseElementModel
isAttributeRequired()Returns a value indicating whether the attribute is required.\CModel
isAttributeSafe()Returns a value indicating whether the attribute is safe for massive assignments.\CModel
isChildOf()Returns whether this element is a direct child of another one.BaseElementModel
isDescendantOf()Returns whether this element is a descendant of another one.BaseElementModel
isEditable()Returns whether the current user can edit the element.TagModel
isNextSiblingOf()Returns whether this element is the direct next sibling of another one.BaseElementModel
isParentOf()Returns whether this element is a direct parent of another one.BaseElementModel
isPrevSiblingOf()Returns whether this element is the direct previous sibling of another one.BaseElementModel
isSiblingOf()Returns whether this element is a sibling of another one.BaseElementModel
offsetExists()Treats custom fields as array offsets.BaseElementModel
offsetGet()Returns the element at the specified offset.\CModel
offsetSet()Sets the element at the specified offset.\CModel
offsetUnset()Unsets the element at the specified offset.\CModel
onAfterConstruct()This event is raised after the model instance is created by new operator.\CModel
onAfterValidate()This event is raised after the validation is performed.\CModel
onBeforeValidate()This event is raised before the validation is performed.\CModel
onUnsafeAttribute()This method is invoked when an unsafe attribute is being massively assigned.\CModel
populateModel()Populates a new model instance with a given set of attributes.BaseElementModel
populateModels()Mass-populates models based on an array of attribute arrays.BaseModel
raiseEvent()Raises an event.\CComponent
rules()Returns this model's validation rules.BaseModel
setAttribute()Sets an attribute's value.BaseModel
setAttributes()Sets multiple attribute values at once.BaseModel
setContent()Sets the content for the element.BaseElementModel
setContentFromPost()Sets the content from post data, calling prepValueFromPost() on the field types.BaseElementModel
setContentPostLocation()Sets the location in POST that the content was pulled from.BaseElementModel
setEagerLoadedElements()Sets some eager-loaded elements on a given handle.BaseElementModel
setId()Returns the tag group's ID.TagModel
setNext()Sets the default next element.BaseElementModel
setParent()Sets the element's parent.BaseElementModel
setPrev()Sets the default previous element.BaseElementModel
setRawPostContent()Sets a field’s raw post content.BaseElementModel
setScenario()Sets the scenario for the model.\CModel
unsetAttributes()Sets the attributes to be null.\CModel
validate()Validates all of the attributes for the current Model. Any attributes that fail validation will additionally get logged to the craft/storage/runtime/logs folder with a level of LogLevel::Warning.BaseModel

Protected Methods #

MethodDescriptionDefined By
afterConstruct()This method is invoked after a model instance is created by new operator.\CModel
afterValidate()This method is invoked after validation ends.\CModel
beforeValidate()This method is invoked before validation starts.\CModel
createContent()Creates the content model associated with this element.BaseElementModel
defineAttributes()Defines this model's attributes.TagModel
getFieldByHandle()Returns the field with a given handle.BaseElementModel

Events #

EventDescriptionDefined By
onAfterConstructThis event is raised after the model instance is created by new operator.\CModel
onBeforeValidateThis event is raised before the validation is performed.\CModel
onAfterValidateThis event is raised after the validation is performed.\CModel
onUnsafeAttributeThis method is invoked when an unsafe attribute is being massively assigned.\CModel

Property Details #

fieldLayout #

read-only
public FieldLayoutModel|null getFieldLayout()

Returns the field layout used by this element.

group #

read-only
public TagGroupModel|null getGroup()

Returns the tag's group.

name #

read-only
public string getName(bool $logDeprecationError = true)

Deprecated in 2.3. Use $title instead.

Returns the tag's title.

set #

read-only
public TagGroupModel|null getSet()

Deprecated in 2.0. Use getGroup() instead.

Returns the tag's group.

Method Details #

__toString() #

public function __toString()
{
     return (string)$this->getContent()->title;
}
Returnsstring

Use the tag title as its string representation.

defineAttributes() #

protected function defineAttributes()
{
     return array_merge(parent::defineAttributes(), array(
          'groupId' => AttributeType::Number,
     ));
}
Returnsarray

Defines this model's attributes.

getAttribute() #

public function getAttribute($name, $flattenValue = false)
{
     return parent::getAttribute($name, $flattenValue);
}
$namestringThe attribute’s name.
$flattenValuebool
Returnsmixed

Gets an attribute’s value.

getFieldLayout() #

public function getFieldLayout()
{
     $tagGroup = $this->getGroup();

     if ($tagGroup)
     {
          return $tagGroup->getFieldLayout();
     }
}
ReturnsFieldLayoutModel / null

Returns the field layout used by this element.

getGroup() #

public function getGroup()
{
     if ($this->groupId)
     {
          return craft()->tags->getTagGroupById($this->groupId);
     }
}
ReturnsTagGroupModel / null

Returns the tag's group.

getName() #

public function getName($logDeprecationError = true)
{
    if ($logDeprecationError) {
          craft()->deprecator->log('TagModel::name', 'The Tag ‘name’ property has been deprecated. Use ‘title’ instead.');
     }

     return $this->getContent()->title;
}
$logDeprecationErrorbool
Returnsstring

Deprecated in 2.3. Use $title instead.

Returns the tag's title.

getSet() #

public function getSet()
{
     craft()->deprecator->log('TagModel::getSet()', 'TagModel::getSet() has been deprecated. Use getGroup() instead.');
     return $this->getGroup();
}
ReturnsTagGroupModel / null

Deprecated in 2.0. Use getGroup() instead.

Returns the tag's group.

isEditable() #

public function isEditable()
{
     return true;
}
Returnsbool

Returns whether the current user can edit the element.

populateModel() #

public static function populateModel($values)
{
     // Strip out the element record attributes if this is getting called from a child class based on an Active
     // Record result eager-loaded with the ElementRecord
     if (isset($values['element']))
     {
          $elementAttributes = $values['element'];
          unset($values['element']);
     }

     $model = parent::populateModel($values);

     // Now set those ElementRecord attributes
     if (isset($elementAttributes))
     {
          if (isset($elementAttributes['i18n']))
          {
               $model->setAttributes($elementAttributes['i18n']);
               unset($elementAttributes['i18n']);
          }

          $model->setAttributes($elementAttributes);
     }

     return $model;
}
$valuesmixed
ReturnsBaseModel

Populates a new model instance with a given set of attributes.

setId() #

public function setId()
{
     craft()->deprecator->log('TagModel::setId', 'Tags’ ‘setId’ property has been deprecated. Use ‘groupId’ instead.');
     return $this->groupId;
}
Returnsint / null

Deprecated in 2.0. Use 'groupId' instead.

Returns the tag group's ID.