From 105b5ce52bee19f19e04e5f697559039432bcd3d Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 5 Sep 2023 10:16:48 +1200 Subject: [PATCH] ENH Allow disabling of help_links --- code/LeftAndMain.php | 17 +++++++++++------ tests/php/LeftAndMainTest.php | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index b180e23f5..87c04f363 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -1863,6 +1863,8 @@ public function SiteConfig() /** * The urls used for the links in the Help dropdown in the backend * + * Set this to `false` via yml config if you do not want to show any help links + * * @config * @var array */ @@ -1889,13 +1891,16 @@ public function getHelpLinks() } }); - foreach ($helpLinks as $key => $value) { - $translationKey = str_replace(' ', '', $key ?? ''); + // Setting the `help_links` config to `false` means no help links will show + if (is_array($helpLinks)) { + foreach ($helpLinks as $key => $value) { + $translationKey = str_replace(' ', '', $key ?? ''); - $formattedLinks[] = [ - 'Title' => _t(__CLASS__ . '.' . $translationKey, $key), - 'URL' => $value - ]; + $formattedLinks[] = [ + 'Title' => _t(__CLASS__ . '.' . $translationKey, $key), + 'URL' => $value + ]; + } } return ArrayList::create($formattedLinks); diff --git a/tests/php/LeftAndMainTest.php b/tests/php/LeftAndMainTest.php index 6f60b9dd0..91d4166f1 100644 --- a/tests/php/LeftAndMainTest.php +++ b/tests/php/LeftAndMainTest.php @@ -215,6 +215,13 @@ public function testGetHelpLinks() $this->assertEquals('www.silverstripe.org', $silverstripeLink['URL']); } + public function testDisableHelpLinks() + { + Config::modify()->set(LeftAndMain::class, 'help_links', false); + $helpLinks = LeftAndMain::singleton()->getHelpLinks(); + $this->assertCount(0, $helpLinks); + } + /** * @dataProvider provideTestCMSVersionNumber */