Bug 39522

Summary: Add hooks to allow 'Valuebuilder' plugins to be installable
Product: Koha Reporter: Jacob O'Mara <jacob.omara>
Component: Plugin architectureAssignee: Jacob O'Mara <jacob.omara>
Status: Needs Signoff --- QA Contact: Jonathan Druart <jonathan.druart>
Severity: enhancement    
Priority: P5 - low CC: dcook, jonathan.druart, julian.maurice, kkrueger, kyle, lisette, martin.renvoize
Version: unspecified   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 39522: Allow Valuebuilders to be installable as plugins
Bug 39522: Add filtering to the plugin home page for valuebuilders
Mark Hofstetter will be following up with unit tests as we worked on this together.
Bug 39522: Add filtering to the plugin home page for valuebuilders
Mark Hofstetter will be following up with unit tests as we worked on this together.
Bug 39522: Add filtering to the plugin home page for valuebuilders
Bug 39522: Allow Valuebuilders to be installable as plugins
Bug 39522: Add filtering to the plugin home page for valuebuilders
Bug 39522: Add unit tests for valuebuilder plugin hooks
Bug 39522: Allow Valuebuilders to be installable as plugins
Bug 39522: Add filtering to the plugin home page for valuebuilders
Bug 39522: Add unit tests for valuebuilder plugin hooks
Bug 39522: (follow-up) Remove debugging
Bug 39522: (follow-up) Remove closing </html> to allow tidy
Bug 39522: Ignore closing html tag to correctly tidy
Bug 39522: Ignore the whole file for tidy

Description Jacob O'Mara 2025-04-02 09:35:54 UTC
We should allow the cataloguing or 'valuebuilder' plugins to be installable with the standard plugin architecture.
Comment 1 Jacob O'Mara 2025-04-02 10:12:24 UTC Comment hidden (obsolete)
Comment 2 Jacob O'Mara 2025-04-02 10:12:27 UTC Comment hidden (obsolete)
Comment 3 Jacob O'Mara 2025-04-02 11:46:41 UTC Comment hidden (obsolete)
Comment 4 Jacob O'Mara 2025-04-02 11:46:44 UTC Comment hidden (obsolete)
Comment 5 Jacob O'Mara 2025-04-02 13:07:26 UTC Comment hidden (obsolete)
Comment 6 Jacob O'Mara 2025-04-02 13:07:28 UTC Comment hidden (obsolete)
Comment 7 Martin Renvoize (ashimema) 2025-06-24 15:35:29 UTC Comment hidden (obsolete)
Comment 8 Martin Renvoize (ashimema) 2025-06-24 15:35:32 UTC Comment hidden (obsolete)
Comment 9 Martin Renvoize (ashimema) 2025-06-24 15:35:34 UTC Comment hidden (obsolete)
Comment 10 Martin Renvoize (ashimema) 2025-06-26 07:02:59 UTC
We've now got this running in production on our sites at OpenFifth.  The Homosaurus plugin is a great example of using it.

* https://github.com/openfifth/koha-plugin-homosaurus-value-builder
Comment 11 Owen Leonard 2025-06-26 12:41:07 UTC
This looks like it's working correctly but the QA script has lots of complaints
Comment 12 Martin Renvoize (ashimema) 2025-07-12 12:02:53 UTC
Created attachment 184030 [details] [review]
Bug 39522: Allow Valuebuilders to be installable as plugins

This patch adds hooks to allow 'Valuebuilder' plugins to be installable
using the standard plugin architecture for Koha. This enables cataloguing
plugins to be dynamically installed, enabled, and disabled through the
plugin system rather than being hardcoded framework components.

Test plan:
1. Install the example valuebuilder plugin from GitHub
   (https://github.com/Jacobomara901/koha-plugin-value-builder)
2. Go to Administration > Plugins
3. Verify the valuebuilder plugin appears in the plugins list
4. Enable/disable the plugin and confirm the custom valuebuilder
   appears/disappears in the framework configuration
5. Assign the custom valuebuilder to a MARC subfield in the
   bibliographic framework
6. Create/edit a bibliographic record and verify the valuebuilder
   button appears next to the configured subfield
7. Click the valuebuilder button and confirm it functions correctly
8. Disable the plugin and verify the valuebuilder button disappears
9. Re-enable the plugin and confirm functionality is restored
10. Uninstall the plugin and verify it's completely removed

Sponsored-by: Open Fifth <https://openfifth.co.uk>
Co-authored-by: Mark Hofstetter <koha@trust-box.at>
Comment 13 Martin Renvoize (ashimema) 2025-07-12 12:02:55 UTC
Created attachment 184031 [details] [review]
Bug 39522: Add filtering to the plugin home page for valuebuilders

This patch adds filtering functionality to the plugin home page to allow
valuebuilder plugins to be displayed alongside other plugins. This ensures
that valuebuilder plugins are properly integrated into the plugin management
interface and can be easily identified and managed by administrators.

Test plan:
1. Install a valuebuilder plugin (following the test plan from the
   previous patch)
2. Go to Administration > Plugins
3. Verify that the valuebuilder plugin appears in the plugins list
4. Confirm that the plugin shows the correct type/category information
5. Use any available filtering options to verify valuebuilder plugins
   can be filtered appropriately
6. Verify that valuebuilder plugins display the same management options
   (enable/disable/configure) as other plugin types
7. Test that plugin status changes are reflected correctly in the
   filtered view

Co-authored-by: Mark Hofstetter <mark@hofstetter.at>
Comment 14 Martin Renvoize (ashimema) 2025-07-12 12:02:57 UTC
Created attachment 184032 [details] [review]
Bug 39522: Add unit tests for valuebuilder plugin hooks

This patch adds comprehensive unit tests for the new valuebuilder plugin
functionality. The tests verify that plugins can provide valuebuilders
through the get_valuebuilder() method and that FrameworkPlugin can
correctly load and integrate with plugin-based valuebuilders.

The tests use a dedicated TestValuebuilder plugin to ensure realistic
testing scenarios without relying on mocks, following the pattern
established in other plugin hook tests.

Test plan:
1. Run the new test file:
   prove t/db_dependent/Koha/Plugins/Valuebuilder_hooks.t
2. Verify all tests pass (9 tests total)
3. Run all plugin tests to ensure no regressions:
   prove t/db_dependent/Koha/Plugins/
4. Verify all plugin tests still pass (113 tests across 19 files)
5. Test the specific functionality:
   - Verify plugins without get_valuebuilder() method are not found as valuebuilders
   - Verify plugins with get_valuebuilder() method are correctly discovered
   - Verify FrameworkPlugin can load plugin-based valuebuilders
   - Verify JavaScript generation works with plugin valuebuilders
   - Verify plugin enable/disable affects valuebuilder availability
6. Confirm FrameworkPlugin integration tests still pass:
   prove t/db_dependent/FrameworkPlugin.t
Comment 15 Martin Renvoize (ashimema) 2025-07-12 12:02:59 UTC
Created attachment 184033 [details] [review]
Bug 39522: (follow-up) Remove debugging
Comment 16 Martin Renvoize (ashimema) 2025-07-12 12:03:01 UTC
Created attachment 184034 [details] [review]
Bug 39522: (follow-up) Remove closing </html> to allow tidy

I don't understand this.. for the tidy script to run and the qa script
to be happy I had to remove the closing html tag.
Comment 17 Jonathan Druart 2025-07-15 08:02:08 UTC
Created attachment 184071 [details] [review]
Bug 39522: Ignore closing html tag to correctly tidy

The prettier plugin for TT has been adjusted to correctly parse our TT
files: most of them does not have an opening head but have a closing
head, then have an opening body but no closing body.

To avoid the parser to fail we are commenting those lines in a
pre-process step in the plugin, then uncomment them in the tidy script.

https://gitlab.com/koha-community/prettier-plugin-template-toolkit/-/blob/main/src/parser.ts?ref_type=heads#L242
export const preprocess: Parser<Node>["preprocess"] = (text) => {
    return text
        .replace("</head>", "<!--</head>-->")
        .replace(/<body(.*)/, "<!--<body$1-->")
        .replace("</body>", "<!--</body>-->");
};

https://git.koha-community.org/Koha-community/Koha/src/branch/main/misc/devel/tidy.pl#L168
            # Revert the substitutions done by the prettier plugin
            my $content = read_file($file);
            $content =~ s#<!--</head>-->#</head>#g;
            $content =~ s#<!--<body(.*)-->#<body$1#g;
            $content =~ s#<!--</body>-->#</body>#g;

(yes it's a bit messy, but our templates are messy)
Comment 18 Jonathan Druart 2025-07-15 08:03:54 UTC
Created attachment 184072 [details] [review]
Bug 39522: Ignore the whole file for tidy

The prettier plugin for TT has been adjusted to correctly parse our TT
files: most of them does not have an opening head but have a closing
head, then have an opening body but no closing body.

To avoid the parser to fail we are commenting those lines in a
pre-process step in the plugin, then uncomment them in the tidy script.

Which means we actually cannot parse correctly formatted HTML files.

https://gitlab.com/koha-community/prettier-plugin-template-toolkit/-/blob/main/src/parser.ts?ref_type=heads#L242
export const preprocess: Parser<Node>["preprocess"] = (text) => {
    return text
        .replace("</head>", "<!--</head>-->")
        .replace(/<body(.*)/, "<!--<body$1-->")
        .replace("</body>", "<!--</body>-->");
};

https://git.koha-community.org/Koha-community/Koha/src/branch/main/misc/devel/tidy.pl#L168
            # Revert the substitutions done by the prettier plugin
            my $content = read_file($file);
            $content =~ s#<!--</head>-->#</head>#g;
            $content =~ s#<!--<body(.*)-->#<body$1#g;
            $content =~ s#<!--</body>-->#</body>#g;

(yes it's a bit messy, but our templates are messy)