You are here

function dsDisplay::render in Display Suite 6.3

Render content

Parameters

stdClass $object : The object to manipulate.

array $vars (optional): The variables required for rendering.

File

includes/dsDisplay.php, line 277
Class definition for a Display Suite Display object

Class

dsDisplay
The Display Suite Display object

Code

function render(&$object, $vars = array()) {

  // @todo
  // This is a workaround till layouts are implemented
  if (!isset($object->layout)) {
    $object->layout = DS_DEFAULT_LAYOUT;
  }
  $this
    ->getLayout($object->layout);

  // end @todo
  // Sort regions to get them in the right order for rendering
  $this
    ->assignActiveRegions($vars['regions']);
  $this->region_styles = ds_default_value($this->display_settings, 'region_styles');

  // Iterate over the active regions to build the display object
  $count = 0;
  foreach ($this->regions as $region_name => $region) {
    if ($region['#hidden'] == FALSE) {

      // Initialise the region with default values
      $this
        ->regionSetup($region_name);

      // Order region fields by weight
      $this
        ->regionOrderFields($region_name);

      // Loop through fields and extract them from the passed-in object
      foreach ($this->regions[$region_name]['#field_weights'] as $key => $weight) {

        /**
         * Preprocess some field content
         */
        switch ($object->ds_fields[$key]['field_type']) {
          case DS_FIELD_TYPE_PREPROCESS:
            if (!empty($object->ds_fields[$key]['preprocess_settings']['key'])) {
              $object->ds_fields[$key]['content'] = $vars[$key][$object->preprocess_fields[$key]['key']];
            }
            else {
              $object->ds_fields[$key]['content'] = $vars[$key];
            }
            break;
          case DS_FIELD_TYPE_IGNORE:
            $object->ds_fields[$key]['content'] = isset($object->content[$key]['#value']) ? $object->content[$key]['#value'] : '';
            break;
        }

        /**
         * Choose a field rendering pipeline based on the type
         *
         * Groups get content and render within wrapper functions.
         * Fields get content then call the renderer directly.
         */
        switch ($object->ds_fields[$key]['field_type']) {
          case DS_FIELD_TYPE_GROUP:
            $this->regions[$region_name][$key] = ds_render_group($object, $key, $vars);
            break;
          case DS_FIELD_TYPE_MULTIGROUP:
            $this->regions[$region_name][$key] = ds_render_multigroup($object, $key, $vars);
            break;
          default:

            // Set content for this item
            $object->ds_fields[$key]['content'] = ds_get_content($object->ds_fields[$key], $vars, $key);
            $this->regions[$region_name][$key] = ds_render_item($object->ds_fields[$key]);
            break;
        }
      }
    }
  }

  // Add field content to all regions
  $this
    ->regionsAddContent();

  // Plugins.
  ds_plugins_process($this, $object, $vars);

  // Add classes based on regions.
  if ($this
    ->regionIsActive('middle')) {
    $this->regions['middle']['#field_content'] = '<div class="' . $this->api_info['module'] . '-region-middle">' . $this->regions['middle']['#field_content'] . '</div>';
    $middle_class = $module . '-no-sidebars';
    if ($this
      ->regionIsActive('left') && $this
      ->regionIsActive('right')) {
      $middle_class = $module . '-two-sidebars';
    }
    elseif ($this
      ->regionIsActive('left')) {
      $middle_class = $module . '-one-sidebar ' . $module . '-sidebar-left';
    }
    elseif ($this
      ->regionIsActive('right')) {
      $middle_class = $module . '-one-sidebar ' . $module . '-sidebar-right';
    }
    $this
      ->regionAttr('middle', 'class', $middle_class);
    $this
      ->regionAttr('middle', 'class', $this->api_info['module'] . '-region-middle-wrapper');
    $this
      ->regionRemoveAttr('middle', 'class', $this->api_info['module'] . '-region-middle');
  }

  // Clean up regions ready for rendering
  $this
    ->regionsRenderAll();

  // Theme the regions with their content.
  $this
    ->displayFinalise();
  $this
    ->displayRender();
  return $this
    ->content();
}