當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ElementHelper::setValidSlug方法代碼示例

本文整理匯總了PHP中ElementHelper::setValidSlug方法的典型用法代碼示例。如果您正苦於以下問題:PHP ElementHelper::setValidSlug方法的具體用法?PHP ElementHelper::setValidSlug怎麽用?PHP ElementHelper::setValidSlug使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ElementHelper的用法示例。


在下文中一共展示了ElementHelper::setValidSlug方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: saveElement


//.........這裏部分代碼省略.........
                         // Copy the element for this locale
                         $localizedElement = $element->copy();
                         $localizedElement->locale = $localeId;
                         if ($localeRecord->id) {
                             // Keep the original slug
                             $localizedElement->slug = $localeRecord->slug;
                         } else {
                             // Default to the main locale's slug
                             $localizedElement->slug = $element->slug;
                         }
                     }
                     if ($elementType->hasContent()) {
                         if (!$isMainLocale) {
                             $content = null;
                             if (!$isNewElement) {
                                 // Do we already have a content row for this locale?
                                 $content = craft()->content->getContent($localizedElement);
                             }
                             if (!$content) {
                                 $content = craft()->content->createContent($localizedElement);
                                 $content->setAttributes($element->getContent()->getAttributes());
                                 $content->id = null;
                                 $content->locale = $localeId;
                             }
                             $localizedElement->setContent($content);
                         }
                         if (!$localizedElement->getContent()->id) {
                             craft()->content->saveContent($localizedElement, false, false);
                         }
                     }
                     // Capture the original slug, in case it's entirely composed of invalid characters
                     $originalSlug = $localizedElement->slug;
                     // Clean up the slug
                     ElementHelper::setValidSlug($localizedElement);
                     // If the slug was entirely composed of invalid characters, it will be blank now.
                     if ($originalSlug && !$localizedElement->slug) {
                         $localizedElement->slug = $originalSlug;
                         $element->addError('slug', Craft::t('{attribute} is invalid.', array('attribute' => Craft::t('Slug'))));
                         // Don't bother with any of the other locales
                         $success = false;
                         break;
                     }
                     ElementHelper::setUniqueUri($localizedElement);
                     $localeRecord->slug = $localizedElement->slug;
                     $localeRecord->uri = $localizedElement->uri;
                     if ($isMainLocale) {
                         $localeRecord->enabled = (bool) $element->localeEnabled;
                     }
                     $success = $localeRecord->save();
                     if (!$success) {
                         // Pass any validation errors on to the element
                         $element->addErrors($localeRecord->getErrors());
                         // Don't bother with any of the other locales
                         break;
                     }
                 }
                 if ($success) {
                     if (!$isNewElement) {
                         // Delete the rows that don't need to be there anymore
                         craft()->db->createCommand()->delete('elements_i18n', array('and', 'elementId = :elementId', array('not in', 'locale', $localeIds)), array(':elementId' => $element->id));
                         if ($elementType->hasContent()) {
                             craft()->db->createCommand()->delete($element->getContentTable(), array('and', 'elementId = :elementId', array('not in', 'locale', $localeIds)), array(':elementId' => $element->id));
                         }
                     }
                     // Call the field types' onAfterElementSave() methods
                     $fieldLayout = $element->getFieldLayout();
開發者ID:harish94,項目名稱:Craft-Release,代碼行數:67,代碼來源:ElementsService.php


注:本文中的ElementHelper::setValidSlug方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。