BaseElementModel

Base element 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.BaseElementModel
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
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
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 element's title as its string representation.BaseElementModel
__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.BaseElementModel
getFieldValue()Returns the prepped content for a given field.BaseElementModel
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
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
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.BaseElementModel
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
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.BaseElementModel
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 #

ancestors #

read-only
public ElementCriteriaModel getAncestors(int|null $dist = null)

Returns the element's ancestors.

children #

read-only
public ElementCriteriaModel getChildren(mixed $field = null)

Returns the element's children.

content #

public ContentModel getContent()
public null setContent(ContentModel|array $content)

Returns the content for the element.

contentFromPost #

public array getContentFromPost()
public null setContentFromPost(array|string $content)

Returns the raw content from the post data, before it was passed through prepValueFromPost().

contentPostLocation #

public string|null getContentPostLocation()
public string|null setContentPostLocation($contentPostLocation $contentPostLocation)

Returns the location in POST that the content was pulled from.

contentTable #

read-only
public string getContentTable()

Returns the name of the table this element's content is stored in.

cpEditUrl #

read-only
public string|false getCpEditUrl()

Returns the element's CP edit URL.

descendants #

read-only
public ElementCriteriaModel getDescendants(int|null $dist = null)

Returns the element's descendants.

elementType #

read-only
public string getElementType()

Returns the type of element this is.

fieldColumnPrefix #

read-only
public string getFieldColumnPrefix()

Returns the field column prefix this element's content uses.

fieldContext #

read-only
public string getFieldContext()

Returns the field context this element's content uses.

fieldLayout #

read-only
public FieldLayoutModel|null getFieldLayout()

Returns the field layout used by this element.

hasFreshContent #

read-only
public bool getHasFreshContent()

Returns whether the element’s content is "fresh" (unsaved and without validation errors).

link #

read-only
public \Twig_Markup getLink()

Returns an anchor pre-filled with this element's URL and title.

locales #

read-only
public array getLocales()

Returns the locale IDs this element is available in.

next #

public ElementCriteriaModel|null getNext(mixed $criteria = false)
public null setNext(BaseElementModel|false $element)

Returns the next element relative to this one, from a given set of criteria.

nextSibling #

read-only
public BaseElementModel|null getNextSibling()

Returns the element's next sibling.

parent #

public BaseElementModel|null getParent()
public null setParent(BaseElementModel|null $parent)

Get the element's parent.

parents #

read-only
public ElementCriteriaModel getParents(mixed $field = null)

Deprecated in 1.3. Use the relatedTo param instead.

Returns a new ElementCriteriaModel prepped to return this element's same-type parents.

prev #

public ElementCriteriaModel|null getPrev(mixed $criteria = false)
public void setPrev(BaseElementModel|false $element)

Returns the previous element relative to this one, from a given set of criteria.

prevSibling #

read-only
public BaseElementModel|null getPrevSibling()

Returns the element's previous sibling.

rawContent #

read-only
public mixed getRawContent(string|null $fieldHandle = null)

Deprecated in 2.0. Use getContent() instead.

Returns the raw content saved on this entity.

This is now deprecated. Use getContent() to get the ContentModel instead.

ref #

read-only
public string|null getRef()

Returns the reference string to this element.

siblings #

read-only
public ElementCriteriaModel getSiblings()

Returns all of the element's siblings.

status #

read-only
public string|null getStatus()

Returns the element's status.

thumbUrl #

read-only
public string|null getThumbUrl(int|null $size = null)

Returns the URL to the element's thumbnail, if there is one.

title #

read-only
public string getTitle()

Returns the element's title.

totalDescendants #

read-only
public bool getTotalDescendants()

Returns the total number of descendants that the element has.

url #

read-only
public string getUrl()

Returns the element's full URL.

urlFormat #

read-only
public string|null getUrlFormat()

Returns the URL format used to generate this element's URL.

Method Details #

__get() #

public function __get($name)
{
     // Run through the BaseModel/CModel stuff first
     try
     {
          return parent::__get($name);
     }
     catch (\Exception $e)
     {
          // Is $name a set of eager-loaded elements?
          if ($this->hasEagerLoadedElements($name))
          {
               return $this->getEagerLoadedElements($name);
          }

          // Is $name a field handle?
          if ($this->getFieldByHandle($name))
          {
               return $this->getFieldValue($name);
          }

          // Fine, throw the exception
          throw $e;
     }
}
$namestring
Returnsmixed

Getter

__isset() #

public function __isset($name)
{
     if ($name == 'title' || $this->hasEagerLoadedElements($name) || parent::__isset($name) || $this->getFieldByHandle($name))
     {
          return true;
     }
     else
     {
          return false;
     }
}
$namestring
Returnsbool

Treats custom fields as properties.

__toString() #

public function __toString()
{
     $title = (string) $this->getTitle();
     return $title ?: ($this->id ?: get_class($this));
}
Returnsstring

Use the element's title as its string representation.

createContent() #

protected function createContent()
{
     return craft()->content->createContent($this);
}
ReturnsContentModel

The content model associated with this element

Creates the content model associated with this element.

defineAttributes() #

protected function defineAttributes()
{
     return array(
          'id'            => AttributeType::Number,
          'enabled'       => array(AttributeType::Bool, 'default' => true),
          'archived'      => array(AttributeType::Bool, 'default' => false),
          'locale'        => array(AttributeType::Locale, 'default' => craft()->i18n->getPrimarySiteLocaleId()),
          'localeEnabled' => array(AttributeType::Bool, 'default' => true),
          'slug'          => array(AttributeType::String, 'label' => 'Slug'),
          'uri'           => array(AttributeType::String, 'label' => 'URI'),
          'dateCreated'   => AttributeType::DateTime,
          'dateUpdated'   => AttributeType::DateTime,

          'root'          => AttributeType::Number,
          'lft'           => AttributeType::Number,
          'rgt'           => AttributeType::Number,
          'level'         => AttributeType::Number,

          'searchScore'   => AttributeType::Number,
     );
}
Returnsarray

Defines this model's attributes.

getAncestors() #

public function getAncestors($dist = null)
{
     if (!isset($this->_ancestorsCriteria))
     {
          $this->_ancestorsCriteria = craft()->elements->getCriteria($this->elementType);
          $this->_ancestorsCriteria->ancestorOf = $this;
          $this->_ancestorsCriteria->locale     = $this->locale;
     }

     if ($dist)
     {
          return $this->_ancestorsCriteria->ancestorDist($dist);
     }
     else
     {
          return $this->_ancestorsCriteria;
     }
}
$distint / null
ReturnsElementCriteriaModel

Returns the element's ancestors.

getAttribute() #

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

Gets an attribute’s value.

getChildren() #

public function getChildren($field = null)
{
     // Eager-loaded?
     if ($this->hasEagerLoadedElements('children'))
     {
          return $this->getEagerLoadedElements('children');
     }

     // TODO: deprecated
     // Maintain support for the deprecated relationship-focussed getChildren() function for the element types that
     // were around before Craft 1.3
     if (
          ($this->elementType == ElementType::Entry && $this->getSection()->type == SectionType::Channel) ||
          in_array($this->elementType, array(ElementType::Asset, ElementType::GlobalSet, ElementType::Tag, ElementType::User))
     )
     {
          craft()->deprecator->log('BaseElementModel::getChildren()_for_relations', 'Calling getChildren() to fetch an element’s target relations has been deprecated. Use the <a href="http://craftcms.com/docs/relations#the-relatedTo-param">relatedTo</a> param instead.');
          return $this->_getRelChildren($field);
     }
     else
     {
          if (!isset($this->_childrenCriteria))
          {
               $this->_childrenCriteria = $this->getDescendants(1);
          }

          return $this->_childrenCriteria;
     }
}
$fieldmixedIf this function is being used in the deprecated relationship-focused way, $field defines which field (if any) to limit the relationships by.
ReturnsElementCriteriaModel

Returns the element's children.

getContent() #

public function getContent()
{
     if (!isset($this->_content))
     {
          $this->_content = craft()->content->getContent($this);

          if (!$this->_content)
          {
               $this->_content = $this->createContent();
          }
     }

     return $this->_content;
}
ReturnsContentModel

Returns the content for the element.

getContentFromPost() #

public function getContentFromPost()
{
     if (isset($this->_rawPostContent))
     {
          return $this->_rawPostContent;
     }
     else
     {
          return array();
     }
}
Returnsarray

Returns the raw content from the post data, before it was passed through prepValueFromPost().

getContentPostLocation() #

public function getContentPostLocation()
{
     return $this->_contentPostLocation;
}
Returnsstring / null

Returns the location in POST that the content was pulled from.

getContentTable() #

public function getContentTable()
{
     return craft()->content->contentTable;
}
Returnsstring

Returns the name of the table this element's content is stored in.

getCpEditUrl() #

public function getCpEditUrl()
{
     return false;
}
Returnsstring / false

Returns the element's CP edit URL.

getDescendants() #

public function getDescendants($dist = null)
{
     // Eager-loaded?
     if ($this->hasEagerLoadedElements('descendants'))
     {
          return $this->getEagerLoadedElements('descendants');
     }

     if (!isset($this->_descendantsCriteria))
     {
          $this->_descendantsCriteria = craft()->elements->getCriteria($this->elementType);
          $this->_descendantsCriteria->descendantOf = $this;
          $this->_descendantsCriteria->locale       = $this->locale;
     }

     if ($dist)
     {
          return $this->_descendantsCriteria->descendantDist($dist);
     }
     else
     {
          return $this->_descendantsCriteria;
     }
}
$distint / null
ReturnsElementCriteriaModel

Returns the element's descendants.

getEagerLoadedElements() #

public function getEagerLoadedElements($handle)
{
     if (isset($this->_eagerLoadedElements[$handle]))
     {
          ElementHelper::setNextPrevOnElements($this->_eagerLoadedElements[$handle]);

          return $this->_eagerLoadedElements[$handle];
     }

     return null;
}
$handlestringThe handle of the eager-loaded elements
ReturnsBaseElementModel[] / null

The eager-loaded elements, or null

Returns some eager-loaded elements on a given handle.

getElementType() #

public function getElementType()
{
     return $this->elementType;
}
Returnsstring

Returns the type of element this is.

getFieldByHandle() #

protected function getFieldByHandle($handle)
{
     if (!isset($this->_fieldsByHandle) || !array_key_exists($handle, $this->_fieldsByHandle))
     {
          $contentService = craft()->content;

          $originalFieldContext = $contentService->fieldContext;
          $contentService->fieldContext = $this->getFieldContext();

          $this->_fieldsByHandle[$handle] = craft()->fields->getFieldByHandle($handle);

          $contentService->fieldContext = $originalFieldContext;
     }

     return $this->_fieldsByHandle[$handle];
}
$handlestring
ReturnsFieldModel / null

Returns the field with a given handle.

getFieldColumnPrefix() #

public function getFieldColumnPrefix()
{
     return craft()->content->fieldColumnPrefix;
}
Returnsstring

Returns the field column prefix this element's content uses.

getFieldContext() #

public function getFieldContext()
{
     return craft()->content->fieldContext;
}
Returnsstring

Returns the field context this element's content uses.

getFieldLayout() #

public function getFieldLayout()
{
     return craft()->fields->getLayoutByType($this->elementType);
}
ReturnsFieldLayoutModel / null

Returns the field layout used by this element.

getFieldValue() #

public function getFieldValue($fieldHandle)
{
     if (!isset($this->_preppedContent) || !array_key_exists($fieldHandle, $this->_preppedContent))
     {
          $field = $this->getFieldByHandle($fieldHandle);

          if (!$field)
          {
               throw new Exception(Craft::t('No field exists with the handle “{handle}”', array('handle' => $fieldHandle)));
          }

          $content = $this->getContent();

          if (isset($content->$fieldHandle))
          {
               $value = $content->$fieldHandle;
          }
          else
          {
               $value = null;
          }

          // Give the field type a chance to prep the value for use
          $fieldType = $field->getFieldType();

          if ($fieldType)
          {
               $fieldType->element = $this;
               $value = $fieldType->prepValue($value);
          }

          $this->_preppedContent[$fieldHandle] = $value;
     }

     return $this->_preppedContent[$fieldHandle];
}
$fieldHandlestring
Returnsmixed

Returns the prepped content for a given field.

getHasFreshContent() #

public function getHasFreshContent()
{
     return (empty($this->getContent()->id) && !$this->hasErrors());
}
Returnsbool

Whether the element’s content is fresh

Returns whether the element’s content is "fresh" (unsaved and without validation errors).

getLink() #

public function getLink()
{
     $link = '<a href="'.$this->getUrl().'">'.HtmlHelper::encode($this->__toString()).'</a>';
     return TemplateHelper::getRaw($link);
}
Returns\Twig_Markup

Returns an anchor pre-filled with this element's URL and title.

getLocales() #

public function getLocales()
{
     if (craft()->elements->getElementType($this->elementType)->isLocalized())
     {
          return craft()->i18n->getSiteLocaleIds();
     }
     else
     {
          return array(craft()->i18n->getPrimarySiteLocaleId());
     }
}
Returnsarray

Returns the locale IDs this element is available in.

getNext() #

public function getNext($criteria = false)
{
     if ($criteria !== false || !isset($this->_nextElement))
     {
          return $this->_getRelativeElement($criteria, 1);
     }
     else if ($this->_nextElement !== false)
     {
          return $this->_nextElement;
     }
}
$criteriamixed
ReturnsElementCriteriaModel / null

Returns the next element relative to this one, from a given set of criteria.

getNextSibling() #

public function getNextSibling()
{
     if (!isset($this->_nextSibling))
     {
          $criteria = craft()->elements->getCriteria($this->elementType);
          $criteria->nextSiblingOf = $this;
          $criteria->locale        = $this->locale;
          $criteria->status        = null;
          $criteria->localeEnabled = null;
          $this->_nextSibling = $criteria->first();
     }

     return $this->_nextSibling;
}
ReturnsBaseElementModel / null

Returns the element's next sibling.

getParent() #

public function getParent()
{
     if (!isset($this->_parent))
     {
          $parent = $this->getAncestors(1)->status(null)->localeEnabled(null)->first();

          if ($parent)
          {
               $this->_parent = $parent;
          }
          else
          {
               $this->_parent = false;
          }
     }

     if ($this->_parent !== false)
     {
          return $this->_parent;
     }
}
ReturnsBaseElementModel / null

Get the element's parent.

getParents() #

public function getParents($field = null)
{
     craft()->deprecator->log('BaseElementModel::getParents()', 'Calling getParents() to fetch an element’s source relations has been deprecated. Use the <a href="http://craftcms.com/docs/relations#the-relatedTo-param">relatedTo</a> param instead.');

     $criteria = craft()->elements->getCriteria($this->elementType);
     $criteria->parentOf    = $this;
     $criteria->parentField = $field;
     return $criteria;
}
$fieldmixed
ReturnsElementCriteriaModel

Deprecated in 1.3. Use the relatedTo param instead.

Returns a new ElementCriteriaModel prepped to return this element's same-type parents.

getPrev() #

public function getPrev($criteria = false)
{
     if ($criteria !== false || !isset($this->_prevElement))
     {
          return $this->_getRelativeElement($criteria, -1);
     }
     else if ($this->_prevElement !== false)
     {
          return $this->_prevElement;
     }
}
$criteriamixed
ReturnsElementCriteriaModel / null

Returns the previous element relative to this one, from a given set of criteria.

getPrevSibling() #

public function getPrevSibling()
{
     if (!isset($this->_prevSibling))
     {
          $criteria = craft()->elements->getCriteria($this->elementType);
          $criteria->prevSiblingOf = $this;
          $criteria->locale        = $this->locale;
          $criteria->status        = null;
          $criteria->localeEnabled = null;
          $this->_prevSibling = $criteria->first();
     }

     return $this->_prevSibling;
}
ReturnsBaseElementModel / null

Returns the element's previous sibling.

getRawContent() #

public function getRawContent($fieldHandle = null)
{
     craft()->deprecator->log('BaseElementModel::getRawContent()', 'BaseElementModel::getRawContent() has been deprecated. Use getContent() instead.');

     $content = $this->getContent();

     if ($fieldHandle)
     {
          if (isset($content->$fieldHandle))
          {
               return $content->$fieldHandle;
          }
          else
          {
               return null;
          }
     }
     else
     {
          return $content;
     }
}
$fieldHandlestring / null
Returnsmixed

Deprecated in 2.0. Use getContent() instead.

Returns the raw content saved on this entity.

This is now deprecated. Use getContent() to get the ContentModel instead.

getRef() #

public function getRef()
{
}
Returnsstring / null

Returns the reference string to this element.

getSiblings() #

public function getSiblings()
{
     if (!isset($this->_siblingsCriteria))
     {
          $this->_siblingsCriteria = craft()->elements->getCriteria($this->elementType);
          $this->_siblingsCriteria->siblingOf = $this;
          $this->_siblingsCriteria->locale    = $this->locale;
     }

     return $this->_siblingsCriteria;
}
ReturnsElementCriteriaModel

Returns all of the element's siblings.

getStatus() #

public function getStatus()
{
     if ($this->archived)
     {
          return static::ARCHIVED;
     }
     else if (!$this->enabled || !$this->localeEnabled)
     {
          return static::DISABLED;
     }
     else
     {
          return static::ENABLED;
     }
}
Returnsstring / null

Returns the element's status.

getThumbUrl() #

public function getThumbUrl($size = null)
{
     return null;
}
$sizeint / null
Returnsstring / null

Returns the URL to the element's thumbnail, if there is one.

getTitle() #

public function getTitle()
{
     $content = $this->getContent();
     return $content->title;
}
Returnsstring

Returns the element's title.

getTotalDescendants() #

public function getTotalDescendants()
{
     if ($this->hasDescendants())
     {
          return ($this->rgt - $this->lft - 1) / 2;
     }

     return 0;
}
Returnsbool

Returns the total number of descendants that the element has.

getUrl() #

public function getUrl()
{
     if ($this->uri !== null)
     {
          $path = ($this->uri == '__home__') ? '' : $this->uri;
          $url = UrlHelper::getSiteUrl($path, null, null, $this->locale);

          return $url;
     }
}
Returnsstring

Returns the element's full URL.

getUrlFormat() #

public function getUrlFormat()
{
}
Returnsstring / null

Returns the URL format used to generate this element's URL.

hasDescendants() #

public function hasDescendants()
{
     return ($this->lft && $this->rgt && $this->rgt > $this->lft + 1);
}
Returnsbool

Returns whether the element has descendants.

hasEagerLoadedElements() #

public function hasEagerLoadedElements($handle)
{
     return isset($this->_eagerLoadedElements[$handle]);
}
$handlestringThe handle of the eager-loaded elements
Returnsbool

Whether elements have been eager-loaded with the given handle

Returns whether elements have been eager-loaded with a given handle.

isAncestorOf() #

public function isAncestorOf(BaseElementModel $element)
{
     return ($this->root == $element->root && $this->lft < $element->lft && $this->rgt > $element->rgt);
}
$elementBaseElementModel
Returnsbool

Returns whether this element is an ancestor of another one.

isChildOf() #

public function isChildOf(BaseElementModel $element)
{
     return ($this->root == $element->root && $this->level == $element->level + 1 && $this->isDescendantOf($element));
}
$elementBaseElementModel
Returnsbool

Returns whether this element is a direct child of another one.

isDescendantOf() #

public function isDescendantOf(BaseElementModel $element)
{
     return ($this->root == $element->root && $this->lft > $element->lft && $this->rgt < $element->rgt);
}
$elementBaseElementModel
Returnsbool

Returns whether this element is a descendant of another one.

isEditable() #

public function isEditable()
{
     return false;
}
Returnsbool

Returns whether the current user can edit the element.

isNextSiblingOf() #

public function isNextSiblingOf(BaseElementModel $element)
{
     return ($this->root == $element->root && $this->level == $element->level && $this->lft == $element->rgt + 1);
}
$elementBaseElementModel
Returnsbool

Returns whether this element is the direct next sibling of another one.

isParentOf() #

public function isParentOf(BaseElementModel $element)
{
     return ($this->root == $element->root && $this->level == $element->level - 1 && $this->isAncestorOf($element));
}
$elementBaseElementModel
Returnsbool

Returns whether this element is a direct parent of another one.

isPrevSiblingOf() #

public function isPrevSiblingOf(BaseElementModel $element)
{
     return ($this->root == $element->root && $this->level == $element->level && $this->rgt == $element->lft - 1);
}
$elementBaseElementModel
Returnsbool

Returns whether this element is the direct previous sibling of another one.

isSiblingOf() #

public function isSiblingOf(BaseElementModel $element)
{
     if ($this->root == $element->root && $this->level && $this->level == $element->level)
     {
          if ($this->level == 1 || $this->isPrevSiblingOf($element) || $this->isNextSiblingOf($element))
          {
               return true;
          }
          else
          {
               $parent = $this->getParent();

               if ($parent)
               {
                    return $element->isDescendantOf($parent);
               }
          }
     }

     return false;
}
$elementBaseElementModel
Returnsbool

Returns whether this element is a sibling of another one.

offsetExists() #

public function offsetExists($offset)
{
     if ($offset == 'title' || $this->hasEagerLoadedElements($offset) || parent::offsetExists($offset) || $this->getFieldByHandle($offset))
     {
          return true;
     }
     else
     {
          return false;
     }
}
$offsetmixed
Returnsbool

Treats custom fields as array offsets.

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.

setContent() #

public function setContent($content)
{
     if (is_array($content))
     {
          if (!isset($this->_content))
          {
               $this->_content = $this->createContent();
          }

          $this->_content->setAttributes($content);
     }
     else if ($content instanceof ContentModel)
     {
          $this->_content = $content;
     }
}
$contentContentModel / array

Sets the content for the element.

setContentFromPost() #

public function setContentFromPost($content)
{
     if (is_string($content))
     {
          // Keep track of where the post data is coming from, in case any field types need to know where to
          // look in $_FILES
          $this->setContentPostLocation($content);

          $content = craft()->request->getPost($content, array());
     }

     if (!isset($this->_rawPostContent))
     {
          $this->_rawPostContent = array();
     }

     $fieldLayout = $this->getFieldLayout();

     if ($fieldLayout)
     {
          // Make sure $this->_content is set
          $this->getContent();

          foreach ($fieldLayout->getFields() as $fieldLayoutField)
          {
               $field = $fieldLayoutField->getField();

               if ($field)
               {
                    $handle = $field->handle;

                    // Do we have any post data for this field?
                    if (isset($content[$handle]))
                    {
                         $value = $content[$handle];
                         $this->setRawPostContent($handle, $value);
                    }
                    // Were any files uploaded for this field?
                    else if (!empty($this->_contentPostLocation) && UploadedFile::getInstancesByName($this->_contentPostLocation.'.'.$handle))
                    {
                         $value = null;
                    }
                    else
                    {
                         // No data was submitted so just skip this field
                         continue;
                    }

                    // Give the field type a chance to make changes
                    $fieldType = $field->getFieldType();

                    if ($fieldType)
                    {
                         $fieldType->element = $this;
                         $value = $fieldType->prepValueFromPost($value);
                    }

                    // Now set the prepped value on the ContentModel
                    $this->_content->$handle = $value;
               }
          }
     }
}
$contentarray / string

Sets the content from post data, calling prepValueFromPost() on the field types.

setContentPostLocation() #

public function setContentPostLocation($contentPostLocation)
{
     $this->_contentPostLocation = $contentPostLocation;
}
$contentPostLocation$contentPostLocation
Returnsstring / null

Sets the location in POST that the content was pulled from.

setEagerLoadedElements() #

public function setEagerLoadedElements($handle, $elements)
{
     $this->_eagerLoadedElements[$handle] = $elements;
}
$handlestringThe handle to load the elements with in the future
$elementsarrayThe eager-loaded elements

Sets some eager-loaded elements on a given handle.

setNext() #

public function setNext($element)
{
     $this->_nextElement = $element;
}
$elementBaseElementModel / false

Sets the default next element.

setParent() #

public function setParent($parent)
{
     $this->_parent = $parent;

     if ($parent)
     {
          $this->level = $parent->level + 1;
     }
     else
     {
          $this->level = 1;
     }
}
$parentBaseElementModel / null

Sets the element's parent.

setPrev() #

public function setPrev($element)
{
     $this->_prevElement = $element;
}
$elementBaseElementModel / falsereturn void

Sets the default previous element.

setRawPostContent() #

public function setRawPostContent($handle, $value)
{
     $this->_rawPostContent[$handle] = $value;
}
$handlestringThe field handle.
$valuestring / arrayThe posted field value.

Sets a field’s raw post content.