Skip to content

Commit

Permalink
Merge branch '2.2' into 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Apr 20, 2018
2 parents 2c81a62 + 60b8ba9 commit 50f145a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 75 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
language: php

php:
- 5.3
- 5.6

env:
- DB=MYSQL CORE_RELEASE=3

matrix:
include:
- php: 5.4
- php: 5.6
env: DB=PGSQL CORE_RELEASE=3
- php: 5.5
env: DB=MYSQL CORE_RELEASE=3.2
- php: 5.6
env: DB=MYSQL CORE_RELEASE=3.2
env: DB=MYSQL CORE_RELEASE=3

before_script:
- pear -q install --onlyreqdeps pear/PHP_CodeSniffer
Expand Down
2 changes: 1 addition & 1 deletion code/forms/LanguageDropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LanguageDropdownField extends GroupedDropdownField {
* @param string $list Indicates the source language list.
* Can be either Common-English, Common-Native, Locale-English, Locale-Native
*/
function __construct($name, $title, $excludeLocales = array(),
public function __construct($name, $title = null, $excludeLocales = array(),
$translatingClass = 'SiteTree', $list = 'Common-English', $instance = null
) {
$usedLocalesWithTitle = Translatable::get_existing_content_languages($translatingClass);
Expand Down
145 changes: 76 additions & 69 deletions code/model/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,12 @@ public function requireDefaultRecords() {
if(!$obj || $obj->ObsoleteClassName) continue;

$obj->Locale = Translatable::default_locale();
$obj->writeToStage($stage);

$oldMode = Versioned::get_reading_mode();
Versioned::reading_stage($stage);
$obj->writeWithoutVersion();
Versioned::set_reading_mode($oldMode);

$obj->addTranslationGroup($obj->ID);
$obj->destroy();
unset($obj);
Expand Down Expand Up @@ -932,7 +937,7 @@ class_exists('SiteTree')
$fresh = Versioned::get_one_by_stage(
$baseDataClass,
Versioned::current_stage(),
'"ID" = ' . $this->owner->ID,
'"'.$baseDataClass.'"."ID" = ' . $this->owner->ID,
null
);
if ($fresh) {
Expand Down Expand Up @@ -1065,72 +1070,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 = '<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)
);
}
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')) {
$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));
}
}
}
}
}

function updateSettingsFields(&$fields) {
Expand Down Expand Up @@ -1572,15 +1579,15 @@ function AllChildrenIncludingDeleted($context = null) {
function MetaTags(&$tags) {
$template = '<link rel="alternate" type="text/html" title="%s" hreflang="%s" href="%s" />' . "\n";
$translations = $this->owner->getTranslations();
if($translations) {
if($translations->count()) {
$translations = $translations->toArray();
$translations[] = $this->owner;
foreach($translations as $translation) {
$tags .= sprintf($template,
Convert::raw2xml($translation->Title),
i18n::convert_rfc1766($translation->Locale),
$translation->AbsoluteLink()

foreach($translations as $translation) {
$tags .= sprintf($template,
Convert::raw2xml($translation->Title),
i18n::convert_rfc1766($translation->Locale),
$translation->AbsoluteLink()
);
}
}
Expand Down Expand Up @@ -1766,7 +1773,7 @@ static function set_reading_lang($lang) {
* @deprecated 2.4 Use get_reading_locale()
*/
static function get_reading_lang() {
return i18n::get_lang_from_locale(self::get_reading_locale());
return i18n::get_lang_from_locale(self::get_current_locale());
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/TranslatableSiteConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function setUp() {

$this->origLocale = Translatable::default_locale();
Translatable::set_default_locale("en_US");

// Delete any default records created outside of fixtures
SiteConfig::get()->exclude('ID', $this->allFixtureIDs('SiteConfig'))->removeAll();
}

function tearDown() {
Expand Down

0 comments on commit 50f145a

Please sign in to comment.