You are here

function heartbeat_plugins_update_7004 in Heartbeat 7

Reformat the attachment section of the plugins.

File

modules/heartbeat_plugins/heartbeat_plugins.install, line 100
Install file.

Code

function heartbeat_plugins_update_7004() {
  module_load_include('inc', 'heartbeat', 'heartbeat');
  module_load_include('inc', 'heartbeat', 'heartbeat_plugins');
  module_load_include('module', 'ctools');
  ctools_include("export");
  $templates = ctools_export_crud_load_all('heartbeat_messages');
  foreach ($templates as $template) {
    if (!isset($template->attachments['buttons'])) {
      $buttons = array(
        'weight' => array(),
        'settings' => array(),
        'enabled' => array(),
      );
      $content = array(
        'weight' => array(),
        'enabled' => array(),
      );

      // The activity comment plugin
      if (isset($template->attachments['activitycomments']) && $template->attachments['activitycomments']['enabled']) {
        $buttons['weight']['activitycomments'] = -9;
        $buttons['settings']['activitycomments']['activitycomments_node'] = $template->attachments['activitycomments']['activitycomments_node'];
        $buttons['enabled']['activitycomments'] = 'activitycomments';
        $content['weight']['activitycomments'] = -9;
        $content['enabled']['activitycomments'] = 'activitycomments';
      }

      // The activity flag plugin
      if (isset($template->attachments['flagattachment'])) {
        foreach ($template->attachments['flagattachment']['flags'] as $flag) {
          if (!$flag) {
            continue;
          }
          $pluginId = 'flagattachment:' . $flag;
          $buttons['weight'][$pluginId] = -10;
          $buttons['enabled'][$pluginId] = $pluginId;
          if (isset($template->attachments['flagattachment']['flag_count_enabled']) && $template->attachments['flagattachment']['flag_count_enabled']['flags']) {
            $content['weight'][$pluginId] = -10;
            $content['enabled'][$pluginId] = $pluginId;
          }
        }
      }
      $template->attachments = array(
        'buttons' => $buttons,
        'content' => $content,
      );

      // Migrate the configuration for the template.
      ctools_export_crud_save('heartbeat_messages', $template);
    }
  }
}