本文整理汇总了PHP中BaseElementModel::getElementType方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseElementModel::getElementType方法的具体用法?PHP BaseElementModel::getElementType怎么用?PHP BaseElementModel::getElementType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseElementModel
的用法示例。
在下文中一共展示了BaseElementModel::getElementType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepElementContentForSave
/**
* Prepares an element's content for being saved to the database.
*
* @param BaseElementModel $element
* @param FieldLayoutModel $fieldLayout
* @param bool $validate
* @return ContentModel
*/
public function prepElementContentForSave(BaseElementModel $element, FieldLayoutModel $fieldLayout, $validate = true)
{
$elementTypeClass = $element->getElementType();
$elementType = craft()->elements->getElementType($elementTypeClass);
$content = $element->getContent();
if ($validate) {
// Set the required fields from the layout
$requiredFields = array();
if ($elementType->hasTitles()) {
$requiredFields[] = 'title';
}
foreach ($fieldLayout->getFields() as $field) {
if ($field->required) {
$requiredFields[] = $field->fieldId;
}
}
if ($requiredFields) {
$content->setRequiredFields($requiredFields);
}
}
// Give the fieldtypes a chance to clean up the post data
foreach (craft()->fields->getAllFields() as $field) {
$fieldType = craft()->fields->populateFieldType($field);
if ($fieldType) {
$fieldType->element = $element;
$handle = $field->handle;
$content->{$handle} = $fieldType->prepValueFromPost($content->{$handle});
}
}
return $content;
}
示例2: isFresh
/**
* Returns whether this is the first time the element's content has been edited.
*
* @return bool
*/
protected function isFresh()
{
// If this is for a Matrix block, we're more interested in its owner
if (isset($this->element) && $this->element->getElementType() == ElementType::MatrixBlock) {
$element = $this->element->getOwner();
} else {
$element = $this->element;
}
return !$element || empty($element->getContent()->id) && !$element->hasErrors();
}
示例3: indexElementAttributes
/**
* Indexes the attributes of a given element defined by its element type.
*
* @param BaseElementModel $element
* @param string|null $localeId
* @return bool Whether the indexing was a success.
*/
public function indexElementAttributes(BaseElementModel $element, $localeId = null)
{
// Get the element type
$elementTypeClass = $element->getElementType();
$elementType = craft()->elements->getElementType($elementTypeClass);
// Does it have any searchable attributes?
$searchableAttributes = $elementType->defineSearchableAttributes();
if ($elementType->hasTitles()) {
$searchableAttributes[] = 'title';
}
foreach ($searchableAttributes as $attribute) {
$value = $element->{$attribute};
$value = StringHelper::arrayToString($value);
$this->_indexElementKeywords($element->id, $attribute, '0', $localeId, $value);
}
return true;
}
示例4: updateDescendantSlugsAndUris
/**
* Updates an element’s descendants’ slugs and URIs.
*
* @param BaseElementModel $element The element whose descendants should be updated.
* @param bool $updateOtherLocales Whether the element’s other locales should also be updated.
* @param bool $asTask Whether the descendants’ slugs and URIs should be updated via a background task.
*
* @return null
*/
public function updateDescendantSlugsAndUris(BaseElementModel $element, $updateOtherLocales = true, $asTask = false)
{
$criteria = $this->getCriteria($element->getElementType());
$criteria->descendantOf = $element;
$criteria->descendantDist = 1;
$criteria->status = null;
$criteria->localeEnabled = null;
$criteria->locale = $element->locale;
if ($asTask) {
$childIds = $criteria->ids();
if ($childIds) {
craft()->tasks->createTask('UpdateElementSlugsAndUris', null, array('elementId' => $childIds, 'elementType' => $element->getElementType(), 'locale' => $element->locale, 'updateOtherLocales' => $updateOtherLocales, 'updateDescendants' => true));
}
} else {
$children = $criteria->find();
foreach ($children as $child) {
$this->updateElementSlugAndUri($child, $updateOtherLocales, true, false);
}
}
}
示例5: saveElement
/**
* Save Element
*
* @param array $params Parameters
*
* @return BaseElementModel $model
*/
public function saveElement(BaseElementModel $element, Request $request)
{
$element_type = \Craft\craft()->elements->getElementType($element->getElementType());
$result = $element_type->saveElement($element, null);
if (!$result) {
$exception = new RestException();
$exception->setStatus(400)->setMessage('Element could not be stored.');
throw $exception;
}
\Craft\craft()->content->saveContent($element);
return $element;
}
示例6: validateContent
/**
* Validates some content with a given field layout.
*
* @param BaseElementModel $element The element whose content should be validated.
*
* @return bool Whether the element's content validates.
*/
public function validateContent(BaseElementModel $element)
{
$elementType = craft()->elements->getElementType($element->getElementType());
$fieldLayout = $element->getFieldLayout();
$content = $element->getContent();
// Set the required fields from the layout
$attributesToValidate = array('id', 'elementId', 'locale');
$requiredFields = array();
if ($elementType->hasTitles()) {
$requiredFields[] = 'title';
$attributesToValidate[] = 'title';
}
if ($fieldLayout) {
foreach ($fieldLayout->getFields() as $fieldLayoutField) {
$field = $fieldLayoutField->getField();
if ($field) {
$attributesToValidate[] = $field->handle;
if ($fieldLayoutField->required) {
$requiredFields[] = $field->id;
}
}
}
}
if ($requiredFields) {
$content->setRequiredFields($requiredFields);
}
return $content->validate($attributesToValidate);
}
示例7: updateDescendantSlugsAndUris
/**
* Updates an element’s descendants’ slugs and URIs.
*
* @param BaseElementModel $element The element whose descendants should be updated.
*
* @return null
*/
public function updateDescendantSlugsAndUris(BaseElementModel $element)
{
$criteria = $this->getCriteria($element->getElementType());
$criteria->descendantOf = $element;
$criteria->descendantDist = 1;
$criteria->status = null;
$criteria->localeEnabled = null;
$children = $criteria->find();
foreach ($children as $child) {
$this->updateElementSlugAndUri($child);
}
}