本文整理汇总了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();