diff --git a/src/Extension/FluentSiteTreeExtension.php b/src/Extension/FluentSiteTreeExtension.php
index e3cfec18..b38da8e8 100644
--- a/src/Extension/FluentSiteTreeExtension.php
+++ b/src/Extension/FluentSiteTreeExtension.php
@@ -8,12 +8,10 @@
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPResponse;
-use SilverStripe\Core\Convert;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\LiteralField;
-use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
use TractorCow\Fluent\Extension\Traits\FluentAdminTrait;
use TractorCow\Fluent\Model\Locale;
@@ -528,60 +526,4 @@ public function actionComplete($form, $message)
{
return null;
}
-
- /**
- * Augment Localisation tab with clickable locale links to allow easy navigation between page localisations
- *
- * @param $summaryColumns
- * @see FluentExtension::updateFluentCMSFields()
- */
- public function updateLocalisationTabColumns(&$summaryColumns)
- {
- parent::updateLocalisationTabColumns($summaryColumns);
-
- if (!array_key_exists('Title', $summaryColumns)) {
- return;
- }
-
- $controller = Controller::curr();
-
- if (!$controller) {
- return;
- }
-
- $request = $controller->getRequest();
-
- if (!$request) {
- return;
- }
-
- // This is to get URL only, getVars are not part of the URL
- $url = $this->owner->CMSEditLink();
-
- if (!$url) {
- return;
- }
-
- // Pass getVars separately so we can process them later
- $params = $request->getVars();
- $url = Director::makeRelative($url);
-
- $summaryColumns['Title'] = [
- 'title' => 'Title',
- 'callback' => function (Locale $object) use ($url, $params) {
- if (!$object->RecordLocale()) {
- return null;
- }
-
- $recordLocale = $object->RecordLocale();
- $locale = $recordLocale->getLocale();
- $params['l'] = $locale;
- $localeLink = Controller::join_links($url, '?' . http_build_query($params));
- $localeTitle = Convert::raw2xml($recordLocale->getTitle());
- $render = sprintf('%s', $localeLink, $localeTitle);
-
- return DBField::create_field('HTMLVarchar', $render);
- }
- ];
- }
}
diff --git a/src/Extension/Traits/FluentObjectTrait.php b/src/Extension/Traits/FluentObjectTrait.php
index 3ba8139d..26e987fb 100644
--- a/src/Extension/Traits/FluentObjectTrait.php
+++ b/src/Extension/Traits/FluentObjectTrait.php
@@ -2,6 +2,10 @@
namespace TractorCow\Fluent\Extension\Traits;
+use SilverStripe\Admin\CMSEditLinkExtension;
+use SilverStripe\Control\Controller;
+use SilverStripe\Control\Director;
+use SilverStripe\Core\Convert;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig;
@@ -90,7 +94,9 @@ public function augmentDataQueryCreation(
*/
protected function updateFluentCMSFields(FieldList $fields)
{
- if (!$this->owner->ID) {
+ $owner = $this->owner;
+
+ if (!$owner->ID) {
return;
}
@@ -109,12 +115,48 @@ protected function updateFluentCMSFields(FieldList $fields)
'Locale' => 'Locale'
];
+ // Augment Localisation tab with clickable locale links to allow easy navigation between model localisations
+ if ($owner->hasExtension(CMSEditLinkExtension::class)) {
+ $columns->setFieldCasting([
+ // Make sure our links are correctly rendered (valid HTML)
+ 'Title' => 'HTMLVarchar->RAW',
+ ]);
+
+ $controller = Controller::has_curr() ? Controller::curr() : null;
+ $request = $controller?->getRequest();
+
+ // Pass getVars separately so we can process them later
+ $params = $request?->getVars() ?? [];
+
+ // This is to get URL only, getVars are not part of the URL
+ $url = $owner->CMSEditLink();
+ $url = Director::makeRelative($url);
+
+ $summaryColumns['Title'] = [
+ 'title' => 'Title',
+ 'callback' => function (Locale $object) use ($url, $params) {
+ if (!$object->RecordLocale()) {
+ return null;
+ }
+
+ $recordLocale = $object->RecordLocale();
+ $locale = $recordLocale->getLocale();
+ $params['l'] = $locale;
+ $localeLink = Controller::join_links($url, '?' . http_build_query($params));
+ $localeTitle = Convert::raw2xml($recordLocale->getTitle());
+ $render = sprintf('%s', $localeLink, $localeTitle);
+
+ return $render;
+ }
+ ];
+ }
+
// Let extensions override columns
- $this->owner->extend('updateLocalisationTabColumns', $summaryColumns);
+ $owner->extend('updateLocalisationTabColumns', $summaryColumns);
$columns->setDisplayFields($summaryColumns);
// Let extensions override components
- $this->owner->extend('updateLocalisationTabConfig', $config);
+ $owner->extend('updateLocalisationTabConfig', $config);
// Add gridfield to tab / fields
$gridField = GridField::create(