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 hooks to alter Mosaico plugins #470

Merged
merged 2 commits into from
Nov 21, 2021

Conversation

olayiwola-compucorp
Copy link
Contributor

Mosaico supports adding custom plugins to the Mosaico object during initialization as stated here. but currently, this extension doesn't allow other extensions to add custom plugins to Mosaico during initialization as the plugins array is empty by default.

This PR adds a new hook named hook_civicrm_mosaicoPlugin that can be used by other modules to add plugins to the Mosaico object during initialization.

Example usage:

/**
 * Implements hook_civicrm_mosaicoPlugin().
 */
function examplemosaico_civicrm_mosaicoPlugin(&$plugins) {
    $plugins[] = _examplemosaico_alert_plugin();
}
  
/**
 * Example plugin.
 */  
function _examplemosaico_alert_plugin(){
    $plugin = <<< JS
        function(vm) {
            alert("test-plugin");
            return {
                    init: function(vm){alert("init");}, 
                    dispose:  function(vm){alert("dispose");}
                }  
        }
    JS;

    return $plugin;
}

The developer decides on how/where to get their JavaScript code, this is just an example.

@totten
Copy link
Collaborator

totten commented Nov 16, 2021

+1 for the concept of allowing plugins via hook

@mattwire
Copy link
Collaborator

@olayiwola-compucorp Can you please document this hook in docs/api.md - when that is done we can merge this PR.

@olayiwola-compucorp
Copy link
Contributor Author

@mattwire Done

@mattwire
Copy link
Collaborator

Thankyou @olayiwola-compucorp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants