You are here

public function sweaver_plugin_palettes::sweaver_form in Sweaver 6

Same name and namespace in other branches
  1. 7 plugins/sweaver_plugin_palettes/sweaver_plugin_palettes.inc \sweaver_plugin_palettes::sweaver_form()

Frontend form.

Overrides sweaver_plugin::sweaver_form

File

plugins/sweaver_plugin_palettes/sweaver_plugin_palettes.inc, line 45
Palettes plugin.

Class

sweaver_plugin_palettes
@file Palettes plugin.

Code

public function sweaver_form() {
  $current_style = Sweaver::get_instance()
    ->get_current_style();
  $active_palette = isset($current_style->palette) ? $current_style->palette : '';
  global $base_path;
  $form = array();
  $containers = '';
  $theme_key = Sweaver::get_instance()
    ->get_theme_key();
  $theme_info = sweaver_get_theme_info($theme_key);
  if (isset($theme_info['sweaver']['palettes'])) {

    // Combine all properties in containers.
    $i = 0;
    $container_count = 1;
    $container_total = ceil(count($theme_info['sweaver']['palettes']) / 5);
    $containers .= '<div class="container-wrapper">';
    foreach ($theme_info['sweaver']['palettes'] as $key => $palette) {
      if ($i == 0) {

        // Add first/last classes to the containers.
        $container_class = '';
        if ($container_count == 1) {
          $container_class .= ' container-first';
        }
        if ($container_total == $container_count) {
          $container_class .= ' container-last';
        }
        $containers .= '<div class="container ' . $container_class . '"><div class="container-inner">';
      }

      // Add the actual content.
      $extra_class = $active_palette == $key ? ' active' : '';
      $containers .= '<div id="palette-' . $key . '" class="colors clear-block' . $extra_class . '">';
      foreach ($palette['colors'] as $color) {
        $containers .= '<div class="color" style="background-color:' . $color . ' !important">' . $color . '</div>';
      }
      $containers .= '<div class="name">' . $palette['name'] . '</div>';

      // Add a hidden field with the path to the css file.
      $containers .= '<div class="file" style="display: none;">' . $base_path . drupal_get_path('theme', $theme_key) . '/' . $palette['file'] . '</div>';

      // Add a hidden field with the key.
      $containers .= '<div class="key" style="display: none;">' . $key . '</div>';
      $containers .= '</div>';
      $i++;

      // close the container div if necessary.
      if ($i == 5) {
        $containers .= '</div></div>';
        $container_count++;
        $i = 0;
      }
    }
    if ($i != 0) {
      $containers .= '</div></div>';
    }
    $containers .= '</div>';

    // Add a hidden field that stores the active key to be saved.
    $form['sweaver_plugin_palette'] = array(
      '#type' => 'hidden',
      '#default_value' => $active_palette ? $active_palette : '',
    );
    $form['markup'] = array(
      '#type' => 'markup',
      '#value' => $containers,
    );
  }
  return $form;
}