本文整理汇总了PHP中Translatable::get_original方法的典型用法代码示例。如果您正苦于以下问题:PHP Translatable::get_original方法的具体用法?PHP Translatable::get_original怎么用?PHP Translatable::get_original使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translatable
的用法示例。
在下文中一共展示了Translatable::get_original方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getNewItem
public function getNewItem($id, $setID = true)
{
list($dummy, $className, $parentID, $suffix) = explode('-', $id);
if (!Translatable::is_default_lang()) {
$originalItem = Translatable::get_original($className, Session::get("{$id}_originalLangID"));
if ($setID) {
$originalItem->ID = $id;
} else {
$originalItem->ID = null;
Translatable::creating_from(Session::get($id . '_originalLangID'));
}
return $originalItem;
}
$newItem = new $className();
if (!$suffix) {
$sessionTag = "NewItems." . $parentID . "." . $className;
if (Session::get($sessionTag)) {
$suffix = '-' . Session::get($sessionTag);
Session::set($sessionTag, Session::get($sessionTag) + 1);
} else {
Session::set($sessionTag, 1);
}
$id = $id . $suffix;
}
$newItem->Title = _t('CMSMain.NEW', "New ", PR_MEDIUM, '"New " followed by a className') . $className;
$newItem->URLSegment = "new-" . strtolower($className);
$newItem->ClassName = $className;
$newItem->ParentID = $parentID;
// DataObject::fieldExists only checks the current class, not the hierarchy
// This allows the CMS to set the correct sort value
if ($newItem->castingHelperPair('Sort')) {
$newItem->Sort = DB::query("SELECT MAX(Sort) FROM SiteTree WHERE ParentID = '" . Convert::raw2sql($parentID) . "'")->value() + 1;
}
if (Member::currentUser()) {
$newItem->OwnerID = Member::currentUser()->ID;
}
if ($setID) {
$newItem->ID = $id;
}
# Some modules like subsites add extra fields that need to be set when the new item is created
$this->extend('augmentNewSiteTreeItem', $newItem);
return $newItem;
}
示例2: updateCMSFields
function updateCMSFields(FieldSet &$fields) {
if(!$this->stat('enabled', true)) return false;
// add hidden fields for the used language and original record
$fields->push(new HiddenField("Lang", "Lang", $this->getLang()) );
$fields->push(new HiddenField("OriginalID", "OriginalID", $this->owner->OriginalID) );
// if a language other than default language is used, we're in "translation mode",
// hence have to modify the original fields
$isTranslationMode = (Translatable::default_lang() != $this->getLang() && $this->getLang());
if($isTranslationMode) {
$originalLangID = Session::get($this->owner->ID . '_originalLangID');
$translatableFieldNames = $this->getTranslatableFields();
$allDataFields = $fields->dataFields();
$transformation = new Translatable_Transformation(Translatable::get_original($this->owner->class, $this->owner->ID));
// iterate through sequential list of all datafields in fieldset
// (fields are object references, so we can replace them with the translatable CompositeField)
foreach($allDataFields as $dataField) {
if(in_array($dataField->Name(), $translatableFieldNames)) {
//var_dump($dataField->Name());
// if the field is translatable, perform transformation
$fields->replaceField($dataField->Name(), $transformation->transformFormField($dataField));
} else {
// else field shouldn't be editable in translation-mode, make readonly
$fields->replaceField($dataField->Name(), $dataField->performReadonlyTransformation());
}
}
} else {
// if we're not in "translation mode", show a dropdown to create a new translation.
// this action should just be possible when showing the default language,
// you can't create new translations from within a "translation mode" form.
$alreadyTranslatedLangs = array();
foreach ($alreadyTranslatedLangs as $i => $langCode) {
$alreadyTranslatedLangs[$i] = i18n::get_language_name($langCode);
}
$fields->addFieldsToTab(
'Root',
new Tab(_t('Translatable.TRANSLATIONS', 'Translations'),
new HeaderField('CreateTransHeader', _t('Translatable.CREATE', 'Create new translation'), 2),
$langDropdown = new LanguageDropdownField("NewTransLang", _t('Translatable.NEWLANGUAGE', 'New language'), $alreadyTranslatedLangs),
$createButton = new InlineFormAction('createtranslation',_t('Translatable.CREATEBUTTON', 'Create'))
)
);
if (count($alreadyTranslatedLangs)) {
$fields->addFieldsToTab(
'Root.Translations',
new FieldSet(
new HeaderField('ExistingTransHeader', _t('Translatable.EXISTING', 'Existing translations:'), 3),
new LiteralField('existingtrans',implode(', ',$alreadyTranslatedLangs))
)
);
}
$langDropdown->addExtraClass('languageDropdown');
$createButton->addExtraClass('createTranslationButton');
$createButton->includeDefaultJS(false);
}
}