mirror of
https://github.com/silverstripe/silverstripe-translatable
synced 2024-10-22 09:05:59 +00:00
Doc added for method getURLForTranslationAndLocale
Use tabs for indention
This commit is contained in:
parent
36f7d011da
commit
da6fdbb09b
@ -9,7 +9,7 @@ class LanguageDropdownField extends GroupedDropdownField {
|
|||||||
|
|
||||||
private static $allowed_actions = array(
|
private static $allowed_actions = array(
|
||||||
'getLocaleForObject',
|
'getLocaleForObject',
|
||||||
'getURLForTranslationAndLocale'
|
'getURLForTranslationAndLocale'
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,9 +86,9 @@ class LanguageDropdownField extends GroupedDropdownField {
|
|||||||
return array_merge(
|
return array_merge(
|
||||||
parent::getAttributes(),
|
parent::getAttributes(),
|
||||||
array(
|
array(
|
||||||
'data-locale-url' => $this->Link('getLocaleForObject'),
|
'data-locale-url' => $this->Link('getLocaleForObject'),
|
||||||
'data-translation-url' => $this->Link('getURLForTranslationAndLocale')
|
'data-translation-url' => $this->Link('getURLForTranslationAndLocale')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,31 +114,33 @@ class LanguageDropdownField extends GroupedDropdownField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $request
|
* Get the CMS edit url for a translated version of a record
|
||||||
* @return string
|
*
|
||||||
*/
|
* @param $request
|
||||||
function getURLForTranslationAndLocale($request) {
|
* @return url
|
||||||
$id = (int)$request->requestVar('id');
|
*/
|
||||||
$class = Convert::raw2sql($request->requestVar('class'));
|
function getURLForTranslationAndLocale($request) {
|
||||||
$locale = Convert::raw2sql($request->requestVar('requestedLocale'));
|
$id = (int)$request->requestVar('id');
|
||||||
$url = '';
|
$class = Convert::raw2sql($request->requestVar('class'));
|
||||||
if ($id && $class && class_exists($class) && $class::has_extension('Translatable')) {
|
$locale = Convert::raw2sql($request->requestVar('requestedLocale'));
|
||||||
if(($record = $class::get()->byId($id)) && ($translation = $record->getTranslations($locale)->First())) {
|
$url = '';
|
||||||
|
if ($id && $class && class_exists($class) && $class::has_extension('Translatable')) {
|
||||||
|
if(($record = $class::get()->byId($id)) && ($translation = $record->getTranslations($locale)->First())) {
|
||||||
|
|
||||||
$controller = $translation instanceOf SiteTree
|
$controller = $translation instanceOf SiteTree
|
||||||
? singleton('CMSPageEditController')
|
? singleton('CMSPageEditController')
|
||||||
: Controller::curr();
|
: Controller::curr();
|
||||||
|
|
||||||
$url = Controller::join_links(
|
$url = Controller::join_links(
|
||||||
$controller->Link('show'),
|
$controller->Link('show'),
|
||||||
$translation->ID,
|
$translation->ID,
|
||||||
'?locale=' . $translation->Locale
|
'?locale=' . $translation->Locale
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user