From 4ba5353cb4dad143d5af651e81e6279543590d85 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 29 Jul 2026 08:17:40 +0100 Subject: [PATCH] Document singleton pattern changes in customfields handler. See MDL-88176. --- docs/apis/core/customfields/index.md | 2 +- .../version-5.2/apis/core/customfields/index.md | 2 +- versioned_docs/version-5.2/devupdate.md | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/apis/core/customfields/index.md b/docs/apis/core/customfields/index.md index a4644919c..374f9d1b8 100644 --- a/docs/apis/core/customfields/index.md +++ b/docs/apis/core/customfields/index.md @@ -27,7 +27,7 @@ New plugin type `customfield` was also added as part of the Custom fields API. A Component/plugin that uses custom fields must define a **handler class** for each area and a **configuration page**. Handler class must be called `/customfield/_handler` and be placed in autoloaded location `/classes/customfield/_handler.php`. This class must extend **\core_customfield\handler** . Configuration page may be located anywhere. For course custom fields configuration the admin settings page is used [/course/customfield.php](https://github.com/moodle/moodle/blob/main/course/customfield.php). If the area uses `itemid` this page should take `itemid` as a parameter. -Handler has protected constructor, to get a handler call `create()` method. Some areas may choose to return a singleton here: +Handler has protected constructor, to get a handler call `create()` method. The base class implementation returns a cached instance (static cache) here: ```php $handler = HANDLERCLASS::create($itemid); diff --git a/versioned_docs/version-5.2/apis/core/customfields/index.md b/versioned_docs/version-5.2/apis/core/customfields/index.md index a4644919c..374f9d1b8 100644 --- a/versioned_docs/version-5.2/apis/core/customfields/index.md +++ b/versioned_docs/version-5.2/apis/core/customfields/index.md @@ -27,7 +27,7 @@ New plugin type `customfield` was also added as part of the Custom fields API. A Component/plugin that uses custom fields must define a **handler class** for each area and a **configuration page**. Handler class must be called `/customfield/_handler` and be placed in autoloaded location `/classes/customfield/_handler.php`. This class must extend **\core_customfield\handler** . Configuration page may be located anywhere. For course custom fields configuration the admin settings page is used [/course/customfield.php](https://github.com/moodle/moodle/blob/main/course/customfield.php). If the area uses `itemid` this page should take `itemid` as a parameter. -Handler has protected constructor, to get a handler call `create()` method. Some areas may choose to return a singleton here: +Handler has protected constructor, to get a handler call `create()` method. The base class implementation returns a cached instance (static cache) here: ```php $handler = HANDLERCLASS::create($itemid); diff --git a/versioned_docs/version-5.2/devupdate.md b/versioned_docs/version-5.2/devupdate.md index 402912d4b..423c657af 100644 --- a/versioned_docs/version-5.2/devupdate.md +++ b/versioned_docs/version-5.2/devupdate.md @@ -34,3 +34,12 @@ The help descriptions within the Activity Chooser have been significantly update - A new optional string, `modulename_tip`, is available for a supplemental section for best practices, advice, or effective usage tips. Third-party activity modules and resources can adopt the same structure by adding these language strings (`modulename_summary`, `modulename_help`, and `modulename_tip`) to their plugin's language files. These strings should be placed in the plugin's language file, for example, `mod/pluginname/lang/en/pluginname.php`. + +## Custom fields base handler caching {/* #custom-fields-base-handler-caching */} + + + +The base `\core_customfield\handler::create(...)` method now handles static caching and cache reset internally, so any custom caching logic +in `create()` overrides in extending classes should be removed. + +More information about the Custom fields API can be found in the [Custom fields API documentation](./apis/core/customfields/index.md).