From 0fea48a608a9afe91f91f546a436236e83be7a65 Mon Sep 17 00:00:00 2001 From: "3dgoo (Michael)" Date: Thu, 28 Jul 2016 13:37:22 +0930 Subject: [PATCH] Check if object is folder before trying to add cms fields. --- code/model/Translatable.php | 120 ++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/code/model/Translatable.php b/code/model/Translatable.php index 98e10ea..c52e607 100755 --- a/code/model/Translatable.php +++ b/code/model/Translatable.php @@ -1065,72 +1065,74 @@ function updateCMSFields(FieldList $fields) { $alreadyTranslatedLocales[$this->owner->Locale] = $this->owner->Locale; $alreadyTranslatedLocales = array_combine($alreadyTranslatedLocales, $alreadyTranslatedLocales); - // Check if fields exist already to avoid adding them twice on repeat invocations - $tab = $fields->findOrMakeTab('Root.Translations', _t('Translatable.TRANSLATIONS', 'Translations')); - if(!$tab->fieldByName('CreateTransHeader')) { - $tab->push(new HeaderField( - 'CreateTransHeader', - _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($alreadyTranslatedLocales) { - if(!$tab->fieldByName('ExistingTransHeader')) { + if ($fields->hasTabSet()) { + // Check if fields exist already to avoid adding them twice on repeat invocations + $tab = $fields->findOrMakeTab('Root.Translations', _t('Translatable.TRANSLATIONS', 'Translations')); + if(!$tab->fieldByName('CreateTransHeader')) { $tab->push(new HeaderField( - 'ExistingTransHeader', - _t('Translatable.EXISTING', 'Existing translations'), - 3 + 'CreateTransHeader', + _t('Translatable.CREATE', 'Create new translation'), + 2 )); - if (!$tab->fieldByName('existingtrans')) { - $existingTransHTML = ''; - $tab->push(new LiteralField('existingtrans', $existingTransHTML)); } } - } + } } function updateSettingsFields(&$fields) {