Skip to content

Commit 2952b85

Browse files
committed
disabledUtilities config setting
Resolves #14044
1 parent a7b9eb4 commit 2952b85

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

CHANGELOG-WIP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Improved element search performance. ([#14055](https://github.com/craftcms/cms/pull/14055))
55
- Added partial support for field types storing data in JSON columns (excluding MariaDB). ([#13916](https://github.com/craftcms/cms/issues/13916))
66
- “Updating search indexes” jobs are no longer queued when saving elements with change tracking enabled, if no searchable fields or attributes were changed. ([#13917](https://github.com/craftcms/cms/issues/13917))
7+
- Added the `disabledUtilities` config setting. ([#14044](https://github.com/craftcms/cms/discussions/14044))
78
- `resave` commands now pass an empty string (`''`) to fields’ `normalizeValue()` methods when `--to` is set to `:empty:`. ([#13951](https://github.com/craftcms/cms/issues/13951))
89
- The `index-assets/one` and `index-assets/all` commands now accept a `--delete-empty-folders` option. ([#13947](https://github.com/craftcms/cms/discussions/13947))
910
- Added `craft\helpers\ElementHelper::searchableAttributes()`.

src/config/GeneralConfig.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,26 @@ class GeneralConfig extends BaseConfig
954954
*/
955955
public string|array|null $disabledPlugins = null;
956956

957+
/**
958+
* @var string[] Array of utility IDs that should be disabled.
959+
*
960+
* ::: code
961+
* ```php Static Config
962+
* ->disabledUtilities([
963+
* 'updates',
964+
* 'find-replace',
965+
* ])
966+
* ```
967+
* ```shell Environment Override
968+
* CRAFT_DISABLED_UTILITIES=updates,find-replace
969+
* ```
970+
* :::
971+
*
972+
* @group System
973+
* @since 4.6.0
974+
*/
975+
public array $disabledUtilities = [];
976+
957977
/**
958978
* @var bool Whether front end requests should respond with `X-Robots-Tag: none` HTTP headers, indicating that pages should not be indexed,
959979
* and links on the page should not be followed, by web crawlers.
@@ -4097,6 +4117,33 @@ public function disabledPlugins(string|array|null $value): self
40974117
return $this;
40984118
}
40994119

4120+
/**
4121+
* Array of utility IDs that should be disabled.
4122+
*
4123+
* ::: code
4124+
* ```php Static Config
4125+
* ->disabledUtilities([
4126+
* 'updates',
4127+
* 'find-replace',
4128+
* ])
4129+
* ```
4130+
* ```shell Environment Override
4131+
* CRAFT_DISABLED_UTILITIES=updates,find-replace
4132+
* ```
4133+
* :::
4134+
*
4135+
* @group System
4136+
* @param string[] $value
4137+
* @return self
4138+
* @see $disabledUtilities
4139+
* @since 4.6.0
4140+
*/
4141+
public function disabledUtilities(array $value): self
4142+
{
4143+
$this->disabledUtilities = $value;
4144+
return $this;
4145+
}
4146+
41004147
/**
41014148
* Whether front end requests should respond with `X-Robots-Tag: none` HTTP headers, indicating that pages should not be indexed,
41024149
* and links on the page should not be followed, by web crawlers.

src/services/Utilities.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ public function getAllUtilityTypes(): array
9696
]);
9797
$this->trigger(self::EVENT_REGISTER_UTILITY_TYPES, $event);
9898

99-
return $event->types;
99+
$disabledUtilities = array_flip(Craft::$app->getConfig()->getGeneral()->disabledUtilities);
100+
101+
return array_values(array_filter($event->types, function(string $class) use ($disabledUtilities) {
102+
/** @var string|UtilityInterface $class */
103+
return !isset($disabledUtilities[$class::id()]);
104+
}));
100105
}
101106

102107
/**

0 commit comments

Comments
 (0)