You are here

function sweaver_frontend in Sweaver 7

Same name and namespace in other branches
  1. 6 sweaver.module \sweaver_frontend()

Rock 'n' roll: the sweaver editor.

1 string reference to 'sweaver_frontend'
sweaver_page_alter in ./sweaver.module
Implements hook_page_alter().

File

./sweaver.module, line 610
Sweaver functions.

Code

function sweaver_frontend($form, &$form_state) {
  $form = array();
  $weight = 1;
  $form['#plugins'] = array();
  $form['#theme'] = 'sweaver_plugin';
  $form['#attributes'] = array(
    'enctype' => 'multipart/form-data',
  );
  $plugins_order = variable_get('sweaver_plugins_weight', array());
  $sweaver = Sweaver::get_instance();
  foreach ($sweaver
    ->get_plugins_registry(TRUE) as $plugin_name => $plugin) {
    $sweaver_plugin = $sweaver
      ->get_plugin($plugin_name);

    // Calculate weight.
    $default_weight = isset($plugins_order[$plugin_name]) ? $plugins_order[$plugin_name] : $weight++;
    if ($plugin_name == 'sweaver_plugin') {
      $default_weight = -100;
    }
    $form['#plugins_order'][$plugin_name] = $default_weight;
    $form['#plugins_full'][$plugin_name] = $plugin;

    // Form.
    $plugin_form = $sweaver_plugin
      ->sweaver_form();
    if (!empty($plugin_form)) {
      $form[$plugin['name']]['form'] = $plugin_form;
      if (isset($plugin['tab'])) {
        $form[$plugin['name']]['#tab_name'] = isset($plugin['tab']) ? $plugin['tab'] : drupal_ucfirst($plugin_name);
        $form[$plugin['name']]['#tab_description'] = isset($plugin['tab_description']) ? $plugin['tab_description'] : '';
      }
    }
  }

  // Editor messages.
  $messages = sweaver_session();
  sweaver_session(NULL, 'sweaver_editor_messages', TRUE);
  $form['sweaver-editor-messages'] = array(
    '#type' => 'hidden',
    '#value' => trim($messages),
  );
  $form['#current_theme'] = $sweaver
    ->get_theme_key();
  $form['destination'] = array(
    '#type' => 'hidden',
    '#value' => $_GET['q'],
  );
  return $form;
}