Skip to content

Commit

Permalink
Add hooks to alter Mosaico plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
olayiwola-compucorp committed Sep 30, 2021
1 parent 31802f7 commit af38d56
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions CRM/Mosaico/Page/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function run() {
$this->createMosaicoConfig(),
defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0
));
$smarty->assign('mosaicoPlugins', $this->getMosaicoPlugins());
echo $smarty->fetch(self::getTemplateFileName());
CRM_Utils_System::civiExit();
}
Expand Down Expand Up @@ -152,4 +153,26 @@ protected function getMaxFileSize() {
return (int) min($iniVal, $settingVal);
}

/**
* Gets the plugins for `Mosaico.init()`.
*
* @return array
*/
public function getMosaicoPlugins() {
$plugins = [];

// Allow plugins to be added by a hook.
if (class_exists('\Civi\Core\Event\GenericHookEvent')) {
\Civi::dispatcher()->dispatch('hook_civicrm_mosaicoPlugin',
\Civi\Core\Event\GenericHookEvent::create([
'plugins' => &$plugins,
])
);
}

$plugins = '[ ' . implode(',', $plugins) . ' ]';

return $plugins;
}

}
2 changes: 1 addition & 1 deletion templates/CRM/Mosaico/Page/Editor.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
return;
}

var plugins;
var plugins = {/literal}{$mosaicoPlugins}{literal};
// A basic plugin that expose the "viewModel" object as a global variable.
// plugins = [function(vm) {window.viewModel = vm;}];
var config = {/literal}{$mosaicoConfig}{literal};
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Mosaico/Page/EditorIframe.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
return;
}

var plugins = [];
var plugins = {/literal}{$mosaicoPlugins}{literal};
var config = {/literal}{$mosaicoConfig}{literal};

window.addEventListener('beforeunload', function(e) {
Expand Down

0 comments on commit af38d56

Please sign in to comment.