function heartbeat_plugins_heartbeat_theme_alter in Heartbeat 7
Implementation of hook_heartbeat_theme_alter().
In this phase we want to tell all plugins attached to a message they can perform any loading tasks or any other data that needs to be available to later display (E.g. buttons and content).
File
- modules/
heartbeat_plugins/ heartbeat_plugins.module, line 377
Code
function heartbeat_plugins_heartbeat_theme_alter(&$messages, HeartbeatStream $stream) {
// Evaluate each message to attach plugin content or buttons.
foreach (array_keys($messages) as $key) {
$pluginLoaders = array();
if (isset($messages[$key]->template->attachments['buttons'])) {
foreach ($messages[$key]->template->attachments['buttons']['enabled'] as $id => $enabled) {
if ($enabled) {
$pluginLoaders[$id] = $id;
}
}
}
if (isset($messages[$key]->template->attachments['content'])) {
foreach ($messages[$key]->template->attachments['content']['enabled'] as $id => $enabled) {
if ($enabled) {
$pluginLoaders[$id] = $id;
}
}
}
// Alter the messages by attaching buttons.
foreach ($pluginLoaders as $pluginId => $info) {
$parts = explode(":", $pluginId);
$pluginName = $parts[0];
$name = isset($parts[1]) ? $parts[1] : NULL;
// Prepare a PluginWrapper.
$pluginWrapper = heartbeat_plugins_get_plugin($pluginName);
if (!is_object($pluginWrapper)) {
continue;
}
// Get a plugin to work with.
$plugin = $pluginWrapper
->getPlugin();
// TODO This needs a check if the plugin is enabled (in this context).
if ($plugin instanceof HeartbeatBasePlugin) {
$plugin
->setStream($stream);
}
// Load attachments.
$plugin
->loadAttachments($messages[$key], $name);
}
}
}