Skip to content

Commit 5b9d0ed

Browse files
authored
Merge pull request #1661 from paulholden/customfields-singleton
Document singleton pattern changes in customfields handler.
2 parents da8915b + 4ba5353 commit 5b9d0ed

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

docs/apis/core/customfields/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ New plugin type `customfield` was also added as part of the Custom fields API. A
2727

2828
Component/plugin that uses custom fields must define a **handler class** for each area and a **configuration page**. Handler class must be called `<PLUGINNAME>/customfield/<AREA>_handler` and be placed in autoloaded location `<PLUGINDIR>/classes/customfield/<AREA>_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.
2929

30-
Handler has protected constructor, to get a handler call `create()` method. Some areas may choose to return a singleton here:
30+
Handler has protected constructor, to get a handler call `create()` method. The base class implementation returns a cached instance (static cache) here:
3131

3232
```php
3333
$handler = HANDLERCLASS::create($itemid);

versioned_docs/version-5.2/apis/core/customfields/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ New plugin type `customfield` was also added as part of the Custom fields API. A
2727

2828
Component/plugin that uses custom fields must define a **handler class** for each area and a **configuration page**. Handler class must be called `<PLUGINNAME>/customfield/<AREA>_handler` and be placed in autoloaded location `<PLUGINDIR>/classes/customfield/<AREA>_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.
2929

30-
Handler has protected constructor, to get a handler call `create()` method. Some areas may choose to return a singleton here:
30+
Handler has protected constructor, to get a handler call `create()` method. The base class implementation returns a cached instance (static cache) here:
3131

3232
```php
3333
$handler = HANDLERCLASS::create($itemid);

versioned_docs/version-5.2/devupdate.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ The help descriptions within the Activity Chooser have been significantly update
3434
- A new optional string, `modulename_tip`, is available for a supplemental section for best practices, advice, or effective usage tips.
3535

3636
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`.
37+
38+
## Custom fields base handler caching {/* #custom-fields-base-handler-caching */}
39+
40+
<Since version="5.2" issueNumber="MDL-88176" />
41+
42+
The base `\core_customfield\handler::create(...)` method now handles static caching and cache reset internally, so any custom caching logic
43+
in `create()` overrides in extending classes should be removed.
44+
45+
More information about the Custom fields API can be found in the [Custom fields API documentation](./apis/core/customfields/index.md).

0 commit comments

Comments
 (0)