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


PHP ElementHelper::createSlug方法代码示例

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


在下文中一共展示了ElementHelper::createSlug方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: safeUp

 public function safeUp()
 {
     //First get all option types and values and make dropdown fields
     $alloptionTypes = craft()->db->createCommand()->select('*')->from('market_optiontypes')->queryAll();
     $fields = [];
     foreach ($alloptionTypes as $optionType) {
         // Need to know if the field name is already taken
         $exists = craft()->fields->getFieldByHandle(ElementHelper::createSlug($optionType['handle']));
         //make a new field name is field name already taken
         if ($exists && $exists->id) {
             $optionType['handle'] = $optionType['handle'] . " option";
         }
         //Make a new field
         $field = new FieldModel();
         $field->groupId = 1;
         $field->context = 'global';
         $field->name = $optionType['name'];
         $field->handle = ElementHelper::createSlug($optionType['handle']);
         $field->type = "Dropdown";
         // Add the values
         $optionValues = craft()->db->createCommand()->select('*')->from('market_optionvalues')->where('optionTypeId=:id', [':id' => $optionType['id']])->queryAll();
         $options = [];
         foreach ($optionValues as $ov) {
             $value = ['label' => $ov['displayName'], 'value' => $ov['name']];
             $options['options'][] = $value;
         }
         $field->settings = $options;
         //save the field
         craft()->fields->saveField($field);
         $fields[] = $field;
     }
     return true;
 }
开发者ID:aladrach,项目名称:Bluefoot-Craft-Starter,代码行数:33,代码来源:m150616_010101_Market_OptionTypesToFieldsOnVariant.php

示例2: handleMatch

 /**
  * Uses the matched headers to create an anchor for them
  *
  * @param array $matches
  *
  * @return string
  */
 public function handleMatch(array $matches = array())
 {
     $tag = $matches['tag'];
     $text = $matches['text'];
     $slug = ElementHelper::createSlug($text);
     $clean = strip_tags($text);
     $currentHeaderLevel = (int) substr($tag, 1, 1);
     if ($this->startingHeaderLevel) {
         $tag = sprintf('h%s', min(6, $currentHeaderLevel + ($this->startingHeaderLevel - 1)));
     }
     return "<{$tag} id=\"{$slug}\">{$text} <a class=\"anchor\" href=\"#{$slug}\" title=\"{$clean}\">#</a></{$tag}>";
 }
开发者ID:kamicrafted,项目名称:designhub,代码行数:19,代码来源:DoxterHeaderParser.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: _parseFile

 /**
  * Open file and parse translate tags.
  *
  * @param string               $path
  * @param string               $file
  * @param ElementCriteriaModel $criteria
  *
  * @return array
  */
 protected function _parseFile($path, $file, ElementCriteriaModel $criteria)
 {
     // Collect matches in file
     $occurences = array();
     // Get file contents
     $contents = IOHelper::getFileContents($file);
     // Get extension
     $extension = IOHelper::getExtension($file);
     // Get matches per extension
     foreach ($this->_expressions[$extension] as $regex) {
         // Match translation functions
         if (preg_match_all($regex, $contents, $matches)) {
             // Collect
             foreach ($matches[2] as $original) {
                 // Translate
                 $translation = Craft::t($original, array(), null, $criteria->locale);
                 // Show translation in textfield
                 $field = craft()->templates->render('_includes/forms/text', array('id' => ElementHelper::createSlug($original), 'name' => 'translation[' . $original . ']', 'value' => $translation, 'placeholder' => $translation));
                 // Fill element with translation data
                 $element = TranslateModel::populateModel(array('id' => ElementHelper::createSlug($original), 'original' => $original, 'translation' => $translation, 'source' => $path, 'file' => $file, 'locale' => $criteria->locale, 'field' => $field));
                 // If searching, only return matches
                 if ($criteria->search && !stristr($element->original, $criteria->search) && !stristr($element->translation, $criteria->search)) {
                     continue;
                 }
                 // If wanting one status, ditch the rest
                 if ($criteria->status && $criteria->status != $element->getStatus()) {
                     continue;
                 }
                 // Collect in array
                 $occurences[$original] = $element;
             }
         }
     }
     // Return occurences
     return $occurences;
 }
开发者ID:boboldehampsink,项目名称:translate,代码行数:45,代码来源:TranslateService.php

示例5: 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

示例6: 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

示例7: slugify

 /**
  * Slugify function.
  *
  * @param string $slug
  *
  * @return string
  */
 public function slugify($slug)
 {
     return ElementHelper::createSlug($slug);
 }
开发者ID:boboldehampsink,项目名称:slugify,代码行数:11,代码来源:SlugifyTwigExtension.php

示例8: createHandle

 /**
  * @param string $text
  *
  * @return string
  */
 public function createHandle($text)
 {
     $text = ElementHelper::createSlug($text);
     $words = explode('-', $text);
     $start = array_shift($words);
     if (count($words)) {
         foreach ($words as $word) {
             $start = $start . ucfirst($word);
         }
     }
     return $start;
 }
开发者ID:jackmcgreevy,项目名称:fast,代码行数:17,代码来源:SproutEmailService.php

示例9: prepForElementModel

 public function prepForElementModel(&$fields, EntryModel $element)
 {
     // Set author
     $author = FeedMe_Element::Author;
     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 = FeedMe_Element::Slug;
     if (isset($fields[$slug])) {
         $element->{$slug} = ElementHelper::createSlug($fields[$slug]);
         //unset($fields[$slug]);
     }
     // Set postdate
     $postDate = FeedMe_Element::PostDate;
     if (isset($fields[$postDate])) {
         $d = date_parse($fields[$postDate]);
         $date_string = date('Y-m-d H:i:s', mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']));
         $element->{$postDate} = DateTime::createFromString($date_string, craft()->timezone);
         //unset($fields[$postDate]);
     }
     // Set expiry date
     $expiryDate = FeedMe_Element::ExpiryDate;
     if (isset($fields[$expiryDate])) {
         $d = date_parse($fields[$expiryDate]);
         $date_string = date('Y-m-d H:i:s', mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']));
         $element->{$expiryDate} = DateTime::createFromString($date_string, craft()->timezone);
         //unset($fields[$expiryDate]);
     }
     // Set enabled
     $enabled = FeedMe_Element::Enabled;
     if (isset($fields[$enabled])) {
         $element->{$enabled} = (bool) $fields[$enabled];
         //unset($fields[$enabled]);
     }
     // Set title
     $title = FeedMe_Element::Title;
     if (isset($fields[$title])) {
         $element->getContent()->{$title} = $fields[$title];
         //unset($fields[$title]);
     }
     // Set parent or ancestors
     $parent = FeedMe_Element::Parent;
     $ancestors = FeedMe_Element::Ancestors;
     if (isset($fields[$parent])) {
         $data = $fields[$parent];
         // Don't connect empty fields
         if (!empty($data)) {
             // Find matching element
             $criteria = craft()->elements->getCriteria(ElementType::Entry);
             $criteria->sectionId = $element->sectionId;
             $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])) {
         $data = $fields[$ancestors];
         // 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()->feedMe->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
     return $element;
 }
开发者ID:jamdigital,项目名称:FeedMe,代码行数:87,代码来源:FeedMe_EntryService.php

示例10: 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

示例11: populateEntryModel

 /**
  * Populates a SproutEmail_EntryModel with post data
  *
  * @param SproutEmail_EntryModel $entry
  *
  * @return \Craft\SproutEmail_EntryModel
  */
 protected function populateEntryModel(SproutEmail_EntryModel $entry)
 {
     $entry->campaignId = $this->campaign->id;
     $entry->slug = craft()->request->getPost('slug', $entry->slug);
     $entry->enabled = (bool) craft()->request->getPost('enabled', $entry->enabled);
     $entry->fromName = craft()->request->getPost('sproutEmail.fromName');
     $entry->fromEmail = craft()->request->getPost('sproutEmail.fromEmail');
     $entry->replyTo = craft()->request->getPost('sproutEmail.replyTo');
     $entry->subjectLine = craft()->request->getRequiredPost('subjectLine');
     $entry->getContent()->title = $entry->subjectLine;
     if (empty($entry->slug)) {
         $entry->slug = ElementHelper::createSlug($entry->subjectLine);
     }
     $fieldsLocation = craft()->request->getParam('fieldsLocation', 'fields');
     $entry->setContentFromPost($fieldsLocation);
     $entry->setContentPostLocation($fieldsLocation);
     return $entry;
 }
开发者ID:aladrach,项目名称:Bluefoot-Craft-Starter,代码行数:25,代码来源:SproutEmail_EntryController.php


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