mirror of
https://github.com/silverstripe/silverstripe-translatable
synced 2024-10-22 11:05:59 +02:00
Check if object is folder before trying to add cms fields.
This commit is contained in:
parent
9b2183167f
commit
0fea48a608
@ -1065,69 +1065,71 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
$alreadyTranslatedLocales[$this->owner->Locale] = $this->owner->Locale;
|
$alreadyTranslatedLocales[$this->owner->Locale] = $this->owner->Locale;
|
||||||
$alreadyTranslatedLocales = array_combine($alreadyTranslatedLocales, $alreadyTranslatedLocales);
|
$alreadyTranslatedLocales = array_combine($alreadyTranslatedLocales, $alreadyTranslatedLocales);
|
||||||
|
|
||||||
// Check if fields exist already to avoid adding them twice on repeat invocations
|
if ($fields->hasTabSet()) {
|
||||||
$tab = $fields->findOrMakeTab('Root.Translations', _t('Translatable.TRANSLATIONS', 'Translations'));
|
// Check if fields exist already to avoid adding them twice on repeat invocations
|
||||||
if(!$tab->fieldByName('CreateTransHeader')) {
|
$tab = $fields->findOrMakeTab('Root.Translations', _t('Translatable.TRANSLATIONS', 'Translations'));
|
||||||
$tab->push(new HeaderField(
|
if(!$tab->fieldByName('CreateTransHeader')) {
|
||||||
'CreateTransHeader',
|
$tab->push(new HeaderField(
|
||||||
_t('Translatable.CREATE', 'Create new translation'),
|
'CreateTransHeader',
|
||||||
2
|
_t('Translatable.CREATE', 'Create new translation'),
|
||||||
));
|
2
|
||||||
}
|
|
||||||
if(!$tab->fieldByName('NewTransLang') && !$tab->fieldByName('AllTransCreated')) {
|
|
||||||
$langDropdown = LanguageDropdownField::create(
|
|
||||||
"NewTransLang",
|
|
||||||
_t('Translatable.NEWLANGUAGE', 'New language'),
|
|
||||||
$alreadyTranslatedLocales,
|
|
||||||
'SiteTree',
|
|
||||||
'Locale-English',
|
|
||||||
$this->owner
|
|
||||||
)->addExtraClass('languageDropdown no-change-track');
|
|
||||||
$tab->push($langDropdown);
|
|
||||||
$canAddLocale = (count($langDropdown->getSource()) > 0);
|
|
||||||
|
|
||||||
if($canAddLocale) {
|
|
||||||
// Only add create button if new languages are available
|
|
||||||
$tab->push(
|
|
||||||
$createButton = InlineFormAction::create(
|
|
||||||
'createtranslation',
|
|
||||||
_t('Translatable.CREATEBUTTON', 'Create')
|
|
||||||
)->addExtraClass('createTranslationButton')
|
|
||||||
);
|
|
||||||
$createButton->includeDefaultJS(false); // not fluent API...
|
|
||||||
} else {
|
|
||||||
$tab->removeByName('NewTransLang');
|
|
||||||
$tab->push(new LiteralField(
|
|
||||||
'AllTransCreated',
|
|
||||||
_t('Translatable.ALLCREATED', 'All allowed translations have been created.')
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
if(!$tab->fieldByName('NewTransLang') && !$tab->fieldByName('AllTransCreated')) {
|
||||||
if($alreadyTranslatedLocales) {
|
$langDropdown = LanguageDropdownField::create(
|
||||||
if(!$tab->fieldByName('ExistingTransHeader')) {
|
"NewTransLang",
|
||||||
$tab->push(new HeaderField(
|
_t('Translatable.NEWLANGUAGE', 'New language'),
|
||||||
'ExistingTransHeader',
|
$alreadyTranslatedLocales,
|
||||||
_t('Translatable.EXISTING', 'Existing translations'),
|
'SiteTree',
|
||||||
3
|
'Locale-English',
|
||||||
));
|
$this->owner
|
||||||
if (!$tab->fieldByName('existingtrans')) {
|
)->addExtraClass('languageDropdown no-change-track');
|
||||||
$existingTransHTML = '<ul>';
|
$tab->push($langDropdown);
|
||||||
if ($existingTranslations = $this->getTranslations()) {
|
$canAddLocale = (count($langDropdown->getSource()) > 0);
|
||||||
foreach ($existingTranslations as $existingTranslation) {
|
|
||||||
if ($existingTranslation && $existingTranslation->hasMethod('CMSEditLink')) {
|
if($canAddLocale) {
|
||||||
$existingTransHTML .= sprintf(
|
// Only add create button if new languages are available
|
||||||
'<li><a href="%s">%s</a></li>',
|
$tab->push(
|
||||||
Controller::join_links(
|
$createButton = InlineFormAction::create(
|
||||||
$existingTranslation->CMSEditLink(),
|
'createtranslation',
|
||||||
'?Locale=' . $existingTranslation->Locale
|
_t('Translatable.CREATEBUTTON', 'Create')
|
||||||
),
|
)->addExtraClass('createTranslationButton')
|
||||||
i18n::get_locale_name($existingTranslation->Locale)
|
);
|
||||||
);
|
$createButton->includeDefaultJS(false); // not fluent API...
|
||||||
|
} else {
|
||||||
|
$tab->removeByName('NewTransLang');
|
||||||
|
$tab->push(new LiteralField(
|
||||||
|
'AllTransCreated',
|
||||||
|
_t('Translatable.ALLCREATED', 'All allowed translations have been created.')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($alreadyTranslatedLocales) {
|
||||||
|
if(!$tab->fieldByName('ExistingTransHeader')) {
|
||||||
|
$tab->push(new HeaderField(
|
||||||
|
'ExistingTransHeader',
|
||||||
|
_t('Translatable.EXISTING', 'Existing translations'),
|
||||||
|
3
|
||||||
|
));
|
||||||
|
if (!$tab->fieldByName('existingtrans')) {
|
||||||
|
$existingTransHTML = '<ul>';
|
||||||
|
if ($existingTranslations = $this->getTranslations()) {
|
||||||
|
foreach ($existingTranslations as $existingTranslation) {
|
||||||
|
if ($existingTranslation && $existingTranslation->hasMethod('CMSEditLink')) {
|
||||||
|
$existingTransHTML .= sprintf(
|
||||||
|
'<li><a href="%s">%s</a></li>',
|
||||||
|
Controller::join_links(
|
||||||
|
$existingTranslation->CMSEditLink(),
|
||||||
|
'?Locale=' . $existingTranslation->Locale
|
||||||
|
),
|
||||||
|
i18n::get_locale_name($existingTranslation->Locale)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$existingTransHTML .= '</ul>';
|
||||||
|
$tab->push(new LiteralField('existingtrans', $existingTransHTML));
|
||||||
}
|
}
|
||||||
$existingTransHTML .= '</ul>';
|
|
||||||
$tab->push(new LiteralField('existingtrans', $existingTransHTML));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user