From b57d557bc7a6529e58ad40137ae5f87dd564743d Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 18 Jan 2023 14:07:39 +1300 Subject: [PATCH] ENH Remove unused Translatable code --- code/Controllers/CMSMain.php | 6 ---- code/Controllers/ContentController.php | 41 +------------------------- code/Controllers/ModelAsController.php | 17 ----------- code/Search/SearchForm.php | 39 ------------------------ 4 files changed, 1 insertion(+), 102 deletions(-) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 155d7e9f..12f43be6 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -73,7 +73,6 @@ use SilverStripe\Versioned\Versioned; use SilverStripe\VersionedAdmin\Controllers\CMSPageHistoryViewerController; use SilverStripe\View\ArrayData; use SilverStripe\View\Requirements; -use Translatable; /** * The main "content" area of the CMS. @@ -185,11 +184,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'); diff --git a/code/Controllers/ContentController.php b/code/Controllers/ContentController.php index 2e75ebe7..7b0a2145 100644 --- a/code/Controllers/ContentController.php +++ b/code/Controllers/ContentController.php @@ -30,7 +30,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}. @@ -199,11 +198,6 @@ class ContentController extends Controller // control to a child controller. This allows for the creation of chains of controllers which correspond to a // 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(); // look for a page with this URLSegment @@ -212,10 +206,6 @@ class ContentController extends Controller // url encode unless it's multibyte (already pre-encoded in the database) 'URLSegment' => $filter->getAllowMultibyte() ? $action : rawurlencode($action), ])->first(); - - if (class_exists('Translatable')) { - Translatable::enable_locale_filter(); - } } // we found a page with this URLSegment. @@ -225,25 +215,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()); try { @@ -415,9 +386,6 @@ 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. * * Suitable for insertion into lang= and xml:lang= * attributes in HTML or XHTML output. @@ -426,14 +394,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); } diff --git a/code/Controllers/ModelAsController.php b/code/Controllers/ModelAsController.php index 1fffb669..35cd946d 100644 --- a/code/Controllers/ModelAsController.php +++ b/code/Controllers/ModelAsController.php @@ -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} @@ -112,11 +111,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()) { @@ -132,21 +126,10 @@ 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()}"); } diff --git a/code/Search/SearchForm.php b/code/Search/SearchForm.php index 7bb6654e..c2ede48f 100644 --- a/code/Search/SearchForm.php +++ b/code/Search/SearchForm.php @@ -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; }