Skip to content

Commit

Permalink
FIX Ensure correct link is used when gridfield is readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
AljosaB authored and GuySartorelli committed May 10, 2024
1 parent 8970ea9 commit 126a7df
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "silverstripe-vendormodule",
"require": {
"php": "^8.1",
"silverstripe/framework": "^5",
"silverstripe/framework": "^5.3",
"silverstripe/cms": "^5"
},
"require-dev": {
Expand Down
22 changes: 22 additions & 0 deletions src/Forms/GridFieldSiteTreeViewButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace SilverStripe\Lumberjack\Forms;

use SilverStripe\Forms\GridField\GridFieldViewButton;
use SilverStripe\View\ArrayData;

class GridFieldSiteTreeViewButton extends GridFieldViewButton
{
public function getColumnContent($gridField, $record, $columnName)
{
if (!$record->canView()) {
return null;
}

$data = ArrayData::create([
'Link' => $record->CMSEditLink(),
]);

return $data->renderWith(GridFieldViewButton::class);
}
}
11 changes: 11 additions & 0 deletions src/Model/Lumberjack.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldViewButton;
use SilverStripe\Forms\Tab;
use SilverStripe\Lumberjack\Forms\GridFieldConfig_Lumberjack;
use SilverStripe\Lumberjack\Forms\GridFieldSiteTreeViewButton;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
Expand Down Expand Up @@ -68,6 +70,15 @@ public function updateCMSFields(FieldList $fields)
$this->getLumberjackGridFieldConfig()
);

// Ensure correct link is used when gridfield is readonly
$readonlyComponents = $gridField->getReadonlyComponents();
$viewButtonIndex = array_search(GridFieldViewButton::class, $readonlyComponents);
if ($viewButtonIndex !== false) {
unset($readonlyComponents[$viewButtonIndex]);
}
$readonlyComponents[] = GridFieldSiteTreeViewButton::class;
$gridField->setReadonlyComponents($readonlyComponents);

$tab = Tab::create('ChildPages', $this->getLumberjackTitle(), $gridField);
$fields->insertAfter('Main', $tab);
}
Expand Down

0 comments on commit 126a7df

Please sign in to comment.