function blocks_manage_blocks_form

4.x blocks.module blocks_manage_blocks_form()
5.x blocks.module blocks_manage_blocks_form()

This form lets the user manage the various blocks in the system.

File

modules/blocks/blocks.module, line 54

Code

function blocks_manage_blocks_form() {

  $form = array();

  fp_add_css(fp_get_module_path("blocks") . "/css/blocks.css");

  $selected_section = $_REQUEST ["section"];
  $selected_module = $_REQUEST ["module"];

  // We should have sub-tabs for all the possible sections.  To accomplish this, 
  // we need to get a list of defined sections and regions.    
  $regions = blocks_get_sections_and_regions();
  $tab_array = array();
  $c = 0;
  foreach ($regions as $module => $region_data) {
    foreach ($region_data as $section => $data) {

      if ($selected_section == "" && $c == 0) {
        // No selected section AND this is the first-- select it!
        $selected_section = $section;
        $selected_module = $module;
      }

      $is_active = ($selected_section == $section && $selected_module == $module) ? TRUE : FALSE;

      $tab_array [] = array(
        "title" => $data ["title"],
        "active" => $is_active,
        "on_click" => 'window.location="' . fp_url("admin/config/blocks", "section=$section&module=$module") . '";',
      );

      $c++;
    }
  }

  fp_set_page_sub_tabs($tab_array);

  $form ["module"] = array(
    "type" => "hidden",
    "value" => $selected_module,
  );

  $form ["section"] = array(
    "type" => "hidden",
    "value" => $selected_section,
  );


  // Tell the user how they can use the content module, if it is enabled.
  if (function_exists("content_menu")) {
    $form ["mark" . $m++] = array(
      "value" => t("To add your own custom blocks of generic content, 
                    use the 'content' module. ") . "<br>" . l(t("Add or edit content blocks"), "admin/config/content"),
    );
  }
  else {
    $form ["mark" . $m++] = array(
      "value" => t("To add your own custom blocks of generic content, 
                    use the 'content' module.  Have your administrator
                    enable it to begin using it.")
    );
  }

  // Build the available region options.
  $region_options = array();
  $region_options [""] = t("- Disabled -");
  foreach ($regions [$selected_module][$selected_section]["regions"] as $region => $rtitle) {
    $region_options [$region] = $rtitle ["title"];
  }

  $weight_options = array();
  for ($t = -100; $t <= 100; $t++) {
    $weight_options [$t] = $t;
  }

  // Okay, now we need a list of available blocks in the system.  We will list each one along with 
  // a pulldown list (of available regions on this section) and a weight pulldown.
  $available_blocks = blocks_get_available_blocks();
  $form ["mark" . $m++] = array(
    "value" => "<table class='blocks-table'>",
  );
  foreach ($available_blocks as $module => $blocks) {
    $form ["mark" . $m++] = array(
      "value" => "<tr>
                    <td colspan='10' class='block-module-name'>$module</td>
                </tr>
                <tr>
                  <th>" . t("Block") . "</th>
                  <th>" . t("Region") . "</th>
                  <th>" . t("Weight") . "</th>
                </tr>",
    );

    foreach ($blocks as $delta => $title) {

      $default_region = "";
      $default_weight = "";

      // is this module and delta currently assigned a particular weight or region in this section?
      $res = db_query("SELECT * FROM blocks WHERE section = '?' AND module = '?' AND delta = '?' 
                        ", $selected_section, $module, $delta);
      $cur = db_fetch_array($res);
      $default_region = $cur ["region"];
      $default_weight = $cur ["weight"];


      $form ["block_region~~{$module}~~{$delta}"] = array(
        "type" => "select",
        "options" => $region_options,
        "prefix" => "<tr>
                      <td>$title</td>
                      <td>",
        "suffix" => "</td>",
        "value" => $default_region,
        "no_please_select" => TRUE,
      );

      $form ["block_weight~~{$module}~~{$delta}"] = array(
        "type" => "select",
        "options" => $weight_options,
        "prefix" => "<td>",
        "suffix" => "</td>
                        </tr>",
        "value" => $default_weight,
        "no_please_select" => TRUE,
      );

    }

  }


  $form ["mark" . $m++] = array(
    "value" => "</table>",
  );


  $form ["submit"] = array(
    "type" => "submit",
    "value" => t("Save block positions"),
    "prefix" => "<hr>",
  );


  return $form;
}