From 30cd4047df1ae9fb5801ace59fe5732b8c71531e Mon Sep 17 00:00:00 2001 From: kevingroeger <54183086+kevingroeger@users.noreply.github.com> Date: Thu, 8 Jun 2023 02:22:14 +0200 Subject: [PATCH] Adjust isEnabled method (#10801) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adjust isEnabled method to use config values if present, adjust dev.yml to have a default_enabled key, add is_enabled as a private property for deprecation in cms 6 * remove default_enabled flag again, adjust comments as suggested, remove method signature from isEnabled, fix typo, adjust logic and add fallback value for isEnabled as true * adjust isEnabled method, change static:: to ->enabled as the property is not actually static --------- Co-authored-by: Kevin Gröger --- src/Dev/BuildTask.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Dev/BuildTask.php b/src/Dev/BuildTask.php index 6f6423ccd..9b2659c53 100644 --- a/src/Dev/BuildTask.php +++ b/src/Dev/BuildTask.php @@ -3,6 +3,7 @@ namespace SilverStripe\Dev; use SilverStripe\Control\HTTPRequest; +use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Extensible; use SilverStripe\Core\Injector\Injectable; @@ -32,9 +33,16 @@ abstract class BuildTask */ private static $segment = null; + /** + * Make this non-nullable and change this to `bool` in CMS6 with a value of `true` + * @var bool|null + */ + private static ?bool $is_enabled = null; + /** * @var bool $enabled If set to FALSE, keep it from showing in the list * and from being executable through URL or CLI. + * @deprecated - remove in CMS 6 and rely on $is_enabled instead */ protected $enabled = true; @@ -64,7 +72,12 @@ abstract class BuildTask */ public function isEnabled() { - return $this->enabled; + $isEnabled = $this->config()->get('is_enabled'); + + if ($isEnabled === null) { + return $this->enabled; + } + return $isEnabled; } /**