当前位置: 首页>>代码示例>>PHP>>正文


PHP BaseElementModel::getContent方法代码示例

本文整理汇总了PHP中BaseElementModel::getContent方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseElementModel::getContent方法的具体用法?PHP BaseElementModel::getContent怎么用?PHP BaseElementModel::getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BaseElementModel的用法示例。


在下文中一共展示了BaseElementModel::getContent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:39,代码来源:ContentService.php

示例2: process

 /**
  * Upload and process the result.
  *
  * @param BaseElementModel $element
  * @param AssetFileModel   $asset
  * @param string           $handle
  *
  * @return bool
  */
 public function process(BaseElementModel $element, AssetFileModel $asset, $handle)
 {
     // Check if we have this asset already or upload to YouTube
     if (!($youTubeId = $this->exists($asset))) {
         try {
             $youTubeId = $this->assemble($asset);
         } catch (Exception $e) {
             return $e->getMessage();
         }
     }
     // Get current video's
     $content = $element->getContent()->getAttribute($handle);
     // Make sure content's an array
     $content = is_array($content) ? $content : array();
     // Remove this asset's id from the content
     unset($content[array_search($asset->id, $content)]);
     // Add video to (existing) content
     $element->getContent()->{$handle} = array_merge($content, array($youTubeId));
     // Save the content without validation
     craft()->content->saveContent($element, false);
     // All went well
     return true;
 }
开发者ID:boboldehampsink,项目名称:youtube,代码行数:32,代码来源:YouTubeService.php

示例3: prepForElementModel

 /**
  * Prepare reserved ElementModel values.
  *
  * @param array            &$fields
  * @param BaseElementModel $element
  *
  * @return BaseElementModel
  */
 public function prepForElementModel(array &$fields, BaseElementModel $element)
 {
     // Set slug
     $slug = Import_ElementModel::HandleSlug;
     if (isset($fields[$slug])) {
         $element->{$slug} = ElementHelper::createSlug($fields[$slug]);
         unset($fields[$slug]);
     }
     // Set title
     $title = Import_ElementModel::HandleTitle;
     if (isset($fields[$title])) {
         $element->getContent()->{$title} = $fields[$title];
         unset($fields[$title]);
     }
     // Return element
     return $element;
 }
开发者ID:radarseven,项目名称:import,代码行数:25,代码来源:Import_CategoryService.php

示例4: prepForElementModel

 /**
  * Prepare reserved ElementModel values.
  *
  * @param array            &$fields
  * @param BaseElementModel $element
  *
  * @return BaseElementModel
  */
 public function prepForElementModel(array &$fields, BaseElementModel $element)
 {
     foreach ($fields as $handle => $value) {
         switch ($handle) {
             case Import_ElementModel::HandleLocale:
                 $element->localeEnabled = true;
             case Import_ElementModel::HandleId:
                 $element->{$handle} = $value;
                 break;
             case Import_ElementModel::HandleSlug:
                 $element->{$handle} = ElementHelper::createSlug($value);
                 break;
             case Import_ElementModel::HandleTitle:
                 $element->getContent()->{$handle} = $value;
                 break;
             default:
                 continue 2;
         }
         unset($fields[$handle]);
     }
     return $element;
 }
开发者ID:transomdesign,项目名称:transom-craft-starter,代码行数:30,代码来源:Import_CategoryService.php

示例5: prepForElementModel

 /**
  * Prepare reserved ElementModel values.
  *
  * @param array            &$fields
  * @param BaseElementModel $element
  *
  * @return BaseElementModel
  */
 public function prepForElementModel(array &$fields, BaseElementModel $element)
 {
     // Set author
     $author = Import_ElementModel::HandleAuthor;
     if (isset($fields[$author])) {
         $user = craft()->users->getUserByUsernameOrEmail($fields[$author]);
         $element->{$author} = is_numeric($fields[$author]) ? $fields[$author] : ($user ? $user->id : 1);
         unset($fields[$author]);
     } else {
         $user = craft()->userSession->getUser();
         $element->{$author} = $element->{$author} ? $element->{$author} : ($user ? $user->id : 1);
     }
     // Set slug
     $slug = Import_ElementModel::HandleSlug;
     if (isset($fields[$slug])) {
         $element->{$slug} = ElementHelper::createSlug($fields[$slug]);
         unset($fields[$slug]);
     }
     // Set postdate
     $postDate = Import_ElementModel::HandlePostDate;
     if (isset($fields[$postDate])) {
         $element->{$postDate} = DateTime::createFromString($fields[$postDate], craft()->timezone);
         unset($fields[$postDate]);
     }
     // Set expiry date
     $expiryDate = Import_ElementModel::HandleExpiryDate;
     if (isset($fields[$expiryDate])) {
         $element->{$expiryDate} = DateTime::createFromString($fields[$expiryDate], craft()->timezone);
         unset($fields[$expiryDate]);
     }
     // Set enabled
     $enabled = Import_ElementModel::HandleEnabled;
     if (isset($fields[$enabled])) {
         $element->{$enabled} = (bool) $fields[$enabled];
         unset($fields[$enabled]);
     }
     // Set title
     $title = Import_ElementModel::HandleTitle;
     if (isset($fields[$title])) {
         $element->getContent()->{$title} = $fields[$title];
         unset($fields[$title]);
     }
     // Set parent or ancestors
     $parent = Import_ElementModel::HandleParent;
     $ancestors = Import_ElementModel::HandleAncestors;
     if (isset($fields[$parent])) {
         // Get data
         $data = $fields[$parent];
         // Fresh up $data
         $data = str_replace("\n", '', $data);
         $data = str_replace("\r", '', $data);
         $data = trim($data);
         // Don't connect empty fields
         if (!empty($data)) {
             // Find matching element
             $criteria = craft()->elements->getCriteria(ElementType::Entry);
             $criteria->sectionId = $element->sectionId;
             // Exact match
             $criteria->search = '"' . $data . '"';
             // Return the first found element for connecting
             if ($criteria->total()) {
                 $element->{$parent} = $criteria->first()->id;
             }
         }
         unset($fields[$parent]);
     } elseif (isset($fields[$ancestors])) {
         // Get data
         $data = $fields[$ancestors];
         // Fresh up $data
         $data = str_replace("\n", '', $data);
         $data = str_replace("\r", '', $data);
         $data = trim($data);
         // Don't connect empty fields
         if (!empty($data)) {
             // Get section data
             $section = new SectionModel();
             $section->id = $element->sectionId;
             // This we append before the slugified path
             $sectionUrl = str_replace('{slug}', '', $section->getUrlFormat());
             // Find matching element by URI (dirty, not all structures have URI's)
             $criteria = craft()->elements->getCriteria(ElementType::Entry);
             $criteria->sectionId = $element->sectionId;
             $criteria->uri = $sectionUrl . craft()->import->slugify($data);
             $criteria->limit = 1;
             // Return the first found element for connecting
             if ($criteria->total()) {
                 $element->{$parent} = $criteria->first()->id;
             }
         }
         unset($fields[$ancestors]);
     }
     // Return element
//.........这里部分代码省略.........
开发者ID:radarseven,项目名称:import,代码行数:101,代码来源:Import_EntryService.php

示例6: populateElement

 /**
  * Populate Element
  *
  * @param BaseElementModel $element Element
  * @param Request          $request Request
  *
  * @return BaseElementModel Element
  */
 public function populateElement(BaseElementModel $element, Request $request)
 {
     $fields_key = \Craft\craft()->config->get('contentModelFieldsLocation', 'restfulApi');
     $attributes = $request->getParsedBody();
     $element->setAttributes($attributes);
     if (isset($attributes[$fields_key])) {
         if (isset($attributes[$fields_key]['title'])) {
             $element->getContent()->title = $attributes[$fields_key]['title'];
         }
         $element->setContent($attributes[$fields_key]);
     }
     return $element;
 }
开发者ID:airtype,项目名称:craft-httpmessagesrestmiddleware,代码行数:21,代码来源:ElementService.php

示例7: 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);
 }
开发者ID:kant312,项目名称:sop,代码行数:35,代码来源:ContentService.php

示例8: getEditorHtml

 /**
  * @inheritDoc IElementType::getEditorHtml()
  *
  * @param BaseElementModel $element
  *
  * @return string
  */
 public function getEditorHtml(BaseElementModel $element)
 {
     $html = craft()->templates->renderMacro('_includes/forms', 'textField', array(array('label' => Craft::t('Title'), 'locale' => $element->locale, 'id' => 'title', 'name' => 'title', 'value' => $element->getContent()->title, 'errors' => $element->getErrors('title'), 'first' => true, 'autofocus' => true, 'required' => true)));
     $html .= craft()->templates->renderMacro('_includes/forms', 'textField', array(array('label' => Craft::t('Slug'), 'locale' => $element->locale, 'id' => 'slug', 'name' => 'slug', 'value' => $element->slug, 'errors' => $element->getErrors('slug'), 'required' => true)));
     $html .= parent::getEditorHtml($element);
     return $html;
 }
开发者ID:paulcarvill,项目名称:Convergence-craft,代码行数:14,代码来源:CategoryElementType.php

示例9: prepForElementModel

 /**
  * Prepare reserved ElementModel values.
  *
  * @param array            &$fields
  * @param BaseElementModel $element
  *
  * @return BaseElementModel
  */
 public function prepForElementModel(array &$fields, BaseElementModel $element)
 {
     $author = Import_ElementModel::HandleAuthor;
     $parent = Import_ElementModel::HandleParent;
     $checkAncestors = !isset($fields[$parent]);
     foreach ($fields as $handle => $value) {
         switch ($handle) {
             case Import_ElementModel::HandleLocale:
                 $element->localeEnabled = true;
             case Import_ElementModel::HandleId:
                 $element->{$handle} = $value;
                 break;
             case Import_ElementModel::HandleAuthor:
                 $element->{$handle} = $this->prepAuthorForElement($value);
                 break;
             case Import_ElementModel::HandleSlug:
                 $element->{$handle} = ElementHelper::createSlug($value);
                 break;
             case Import_ElementModel::HandlePostDate:
             case Import_ElementModel::HandleExpiryDate:
                 $element->{$handle} = DateTime::createFromString($value, craft()->timezone);
                 break;
             case Import_ElementModel::HandleEnabled:
                 $element->{$handle} = (bool) $value;
                 break;
             case Import_ElementModel::HandleTitle:
                 $element->getContent()->{$handle} = $value;
                 break;
             case Import_ElementModel::HandleParent:
                 $element->{$handle} = $this->prepareParentForElement($value, $element->sectionId);
                 break;
             case Import_ElementModel::HandleAncestors:
                 if ($checkAncestors) {
                     $element->{$parent} = $this->prepareAncestorsForElement($value, $element->sectionId);
                 }
                 break;
             default:
                 continue 2;
         }
         unset($fields[$handle]);
     }
     // Set default author if not set
     if (!$element->{$author}) {
         $user = craft()->userSession->getUser();
         $element->{$author} = $element->{$author} ? $element->{$author} : ($user ? $user->id : 1);
     }
     // Return element
     return $element;
 }
开发者ID:transomdesign,项目名称:transom-craft-starter,代码行数:57,代码来源:Import_EntryService.php


注:本文中的BaseElementModel::getContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。