ENH Remove references to deprecated Translatable class

This commit is contained in:
Ben Mitchell 2022-11-10 10:26:14 +13:00
parent 7a7c751f7c
commit bf32ad7151
4 changed files with 2 additions and 96 deletions

View File

@ -71,7 +71,6 @@ use SilverStripe\Versioned\ChangeSetItem;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;
use Translatable;
/**
* The main "content" area of the CMS.
@ -183,11 +182,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
protected function init()
{
// set reading lang
if (SiteTree::has_extension('Translatable') && !$this->getRequest()->isAjax()) {
Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages(SiteTree::class) ?? []));
}
parent::init();
Requirements::javascript('silverstripe/cms: client/dist/js/bundle.js');

View File

@ -29,7 +29,6 @@ use SilverStripe\View\ArrayData;
use SilverStripe\View\Parsers\URLSegmentFilter;
use SilverStripe\View\Requirements;
use SilverStripe\View\SSViewer;
use Translatable;
/**
* The most common kind of controller; effectively a controller linked to a {@link DataObject}.
@ -201,9 +200,6 @@ class ContentController extends Controller
// nested URL.
if ($action && SiteTree::config()->nested_urls && !$this->hasAction($action)) {
// See ModelAdController->getNestedController() for similar logic
if (class_exists('Translatable')) {
Translatable::disable_locale_filter();
}
$filter = URLSegmentFilter::create();
@ -214,9 +210,6 @@ class ContentController extends Controller
'URLSegment' => $filter->getAllowMultibyte() ? $action : rawurlencode($action),
])->first();
if (class_exists('Translatable')) {
Translatable::enable_locale_filter();
}
}
// we found a page with this URLSegment.
@ -226,24 +219,6 @@ class ContentController extends Controller
$response = ModelAsController::controller_for($child)->handleRequest($request);
} else {
// If a specific locale is requested, and it doesn't match the page found by URLSegment,
// look for a translation and redirect (see #5001). Only happens on the last child in
// a potentially nested URL chain.
if (class_exists('Translatable')) {
$locale = $request->getVar('locale');
if ($locale
&& i18n::getData()->validate($locale)
&& $this->dataRecord
&& $this->dataRecord->Locale != $locale
) {
$translation = $this->dataRecord->getTranslation($locale);
if ($translation) {
$response = new HTTPResponse();
$response->redirect($translation->Link(), 301);
throw new HTTPResponse_Exception($response);
}
}
}
Director::set_current_page($this->data());
@ -416,9 +391,7 @@ HTML;
/**
* Returns an RFC1766 compliant locale string, e.g. 'fr-CA'.
* Inspects the associated {@link dataRecord} for a {@link SiteTree->Locale} value if present,
* and falls back to {@link Translatable::get_current_locale()} or {@link i18n::default_locale()},
* depending if Translatable is enabled.
* Inspects the current locale with {@link i18n::get_locale()}
*
* Suitable for insertion into lang= and xml:lang=
* attributes in HTML or XHTML output.
@ -427,13 +400,7 @@ HTML;
*/
public function ContentLocale()
{
if ($this->dataRecord && $this->dataRecord->hasExtension('Translatable')) {
$locale = $this->dataRecord->Locale;
} elseif (class_exists('Translatable') && SiteTree::has_extension('Translatable')) {
$locale = Translatable::get_current_locale();
} else {
$locale = i18n::get_locale();
}
$locale = i18n::get_locale();
return i18n::convert_rfc1766($locale);
}

View File

@ -17,7 +17,6 @@ use SilverStripe\Dev\Debug;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\View\Parsers\URLSegmentFilter;
use Translatable;
/**
* ModelAsController deals with mapping the initial request to the first {@link SiteTree}/{@link ContentController}
@ -123,11 +122,6 @@ class ModelAsController extends Controller implements NestedController
throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.');
}
// Find page by link, regardless of current locale settings
if (class_exists('Translatable')) {
Translatable::disable_locale_filter();
}
// url encode unless it's multibyte (already pre-encoded in the database)
$filter = URLSegmentFilter::create();
if (!$filter->getAllowMultibyte()) {
@ -143,21 +137,11 @@ class ModelAsController extends Controller implements NestedController
/** @var SiteTree $sitetree */
$sitetree = DataObject::get_one(SiteTree::class, $conditions);
// Check translation module
// @todo Refactor out module specific code
if (class_exists('Translatable')) {
Translatable::enable_locale_filter();
}
if (!$sitetree) {
$this->httpError(404, 'The requested page could not be found.');
}
// Enforce current locale setting to the loaded SiteTree object
if (class_exists('Translatable') && $sitetree->Locale) {
Translatable::set_current_locale($sitetree->Locale);
}
if (isset($_REQUEST['debug'])) {
Debug::message("Using record #$sitetree->ID of type " . get_class($sitetree) . " with link {$sitetree->Link()}");
}

View File

@ -13,17 +13,11 @@ use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\SS_List;
use Translatable;
/**
* Standard basic search form which conducts a fulltext search on all {@link SiteTree}
* objects.
*
* If multilingual content is enabled through the {@link Translatable} extension,
* only pages the currently set language on the holder for this searchform are found.
* The language is set through a hidden field in the form, which is prepoluated
* with {@link Translatable::get_current_locale()} when then form is constructed.
*
* @see Use ModelController and SearchContext for a more generic search implementation based around DataObject
*/
class SearchForm extends Form
@ -70,12 +64,6 @@ class SearchForm extends Form
);
}
if (class_exists('Translatable')
&& SiteTree::singleton()->hasExtension('Translatable')
) {
$fields->push(new HiddenField('searchlocale', 'searchlocale', Translatable::get_current_locale()));
}
if (!$actions) {
$actions = new FieldList(
new FormAction("results", _t(__CLASS__.'.GO', 'Go'))
@ -130,22 +118,6 @@ class SearchForm extends Form
// Get request data from request handler
$request = $this->getRequestHandler()->getRequest();
// set language (if present)
$locale = null;
$origLocale = null;
if (class_exists('Translatable')) {
$locale = $request->requestVar('searchlocale');
if (SiteTree::singleton()->hasExtension('Translatable') && $locale) {
if ($locale === "ALL") {
Translatable::disable_locale_filter();
} else {
$origLocale = Translatable::get_current_locale();
Translatable::set_current_locale($locale);
}
}
}
$keywords = $request->requestVar('Search');
$andProcessor = function ($matches) {
@ -181,17 +153,6 @@ class SearchForm extends Form
}
}
// reset locale
if (class_exists('Translatable')) {
if (SiteTree::singleton()->hasExtension('Translatable') && $locale) {
if ($locale == "ALL") {
Translatable::enable_locale_filter();
} else {
Translatable::set_current_locale($origLocale);
}
}
}
return $results;
}