function fp_render_content

7.x render.inc fp_render_content($render_array = array(), $bool_include_wrappers = TRUE)
6.x render.inc fp_render_content($render_array = array(), $bool_include_wrappers = TRUE)
5.x render.inc fp_render_content($render_array = array())

This is very similar to fp_get_form / fp_render_form, except in this case we are being passed the completed "render_array", which already contains all of our elements. We will call hooks on it, sort by weights, and then return the rendered HTML.

20 calls to fp_render_content()
admin_display_courses in modules/admin/admin.courses.inc
This function displays all of our courses for us to edit.
admin_display_degrees in modules/admin/admin.degrees.inc
admin_display_groups in modules/admin/admin.groups.inc
This function will display a list of all our groups.
advise_display_history in modules/advise/advise.history.inc
Displays the history tab on screen.
advise_display_view in modules/advise/advise.module
This is the page which actually displays the "view" for the user to see their advising session, or for an advisor to advise them.

... See full list

File

includes/render.inc, line 16

Code

function fp_render_content($render_array = array(), $bool_include_wrappers = TRUE) {

  $rtn = "";

  if (!isset($render_array ["#id"])) {
    // An #id wasn't set, which is required, so we're going to 
    // create one based on the function that called this function.
    $x = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
    $render_array ['#id'] = trim(@$x [1]['class'] . "_" . @$x [1]['function']);
    // If nothing was discovered, just ditch it...
    if ($render_array ['#id'] == "_") {
      unset($render_array ["#id"]);
    }
  }

  // First, check to see if this render array has an "#id" field defined.  This is required.
  $render_id = fp_get_machine_readable(fp_trim(@$render_array ["#id"]));
  if ($render_id == "") {
    fp_add_message(t("The render array supplied does not have an #id field set.  This must be
                     machine-readable and unique.<br>Ex:  \$arr['#id'] = 'advise_course_description_popup';
                     <br>It may be easiest to simply name it after the function which is creating the render array."), "error");
    return "";
  }

  $class = trim((string) @$render_array ['#class']);

  // Any hooks to alter this render array?  
  $modules = modules_implement_hook("content_alter");
  foreach ($modules as $module) {
    call_user_func_array($module . '_content_alter', array(&$render_array, $render_id));
  }

  // Okay, now the fun part.  Re-order the elements by weight.  Lighter weights
  // should float to the top.  Elements w/o a weight listed are assumed to have a weight of 0.
  // Unfortunately we cannot use uasort, as it re-orders our indexes when weights are identical.


  // The first the I want to do is find out, what are the defined weights in this form, if any.
  $defined_weights = array();
  foreach ($render_array as $key => $element) {

    // If we were just passed a string, treat it as plain HTML markup.
    if (!strstr($key, "#") && is_string($element)) {
      $element = array('value' => $element);
      $render_array [$key] = $element; // make sure we pick up any changes we've made      
    }

    if (!is_array($element)) {
      continue;
    }

    if (!isset($element ["weight"])) {
      $element ["weight"] = 0;
    }





    $weight = (float) $element ["weight"];
    if (!in_array($weight, $defined_weights)) {
      $defined_weights [] = $weight;
    }
  }

  // Okay, now sort our weights.
  sort($defined_weights);


  // Before we get to assigning weights, we need to make sure
  // that none of our form elements have a name which might cause us trouble.
  // Namely, no element can be named "submit" (like a button) because it will
  // interfere with our javascript functions.
  $form2 = array();
  foreach ($render_array as $key => $element) {
    $name = $key;
    if ($name == "submit") {
      $name = "btn_submit";
    }

    $form2 [$name] = $element;
  }

  $form = $form2;


  // Okay, now go through the weights and create a new form in THAT order.
  $new_form = array();
  foreach ($defined_weights as $dw) {
    foreach ($form as $key => $element) {

      if (!is_array($element)) {
        $new_form [$key] = $element;
        continue;
      }

      if (!isset($element ["weight"])) {
        $element ["weight"] = 0;
      }
      $weight = (float) $element ["weight"];
      if ($weight == $dw) {
        $new_form [$key] = $element;
      }
    }
  }

  // Okay, we should now be good to go!  
  $render_array = $new_form;

  // We can now proceed with rendering this render_array.  It will be similar to fp_render_form.
  if ($bool_include_wrappers) {
    $rtn .= "<div class='renderapi-content $class' id='render-$render_id'>";
  }

  $rtn .= fp_render_array($render_array);

  if ($bool_include_wrappers) {
    $rtn .= "</div>";
  }

  return $rtn;

}