Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability for plugins to define custom expressions … #1449

Merged

Conversation

bri-gaia
Copy link

…for use in display templates.

@kehh
Copy link
Contributor

kehh commented Jun 26, 2023

Very similar code to this has been in use in production for the past couple of years. Similar to #1450 this moves this functionality into a plugin. The plugin can then register custom functions that can be called:

    public function hookRegisterExpressions($pa_options) {
        $fancy_methods = [
            'fancyfyTheText',
        ];
        foreach ($fancy_methods as $method) {
            $custom = function(...$args) use ($method) {
                if (is_callable("FancyClass::{$method}")){
                    $ret = fancyClass::$method(...$args);
                } else {
                    throw new Exception("Method FancyClass::$method does not exist and cannot be called.");
                }
                return $ret;
            };
            $pa_options['expressions']['FancyText' . $method] = xcallable($custom);
        }

        return $pa_options;
    }

@collectiveaccess collectiveaccess merged commit 2c02571 into collectiveaccess:develop Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants