You are here

function panopoly_magic_process_panels_add_content_modal in Panopoly Magic 7

Process the panels_add_content_modal() to adjust the markup to present the preview

File

./panopoly_magic.module, line 1861

Code

function panopoly_magic_process_panels_add_content_modal(&$vars) {
  $use_preview = variable_get('panopoly_magic_pane_add_preview', PANOPOLY_ADD_PREVIEW_DEFAULT);
  if ($use_preview == PANOPOLY_ADD_PREVIEW_DISABLED) {
    return;
  }
  $content = !empty($vars['categories'][$vars['category']]['content']) ? $vars['categories'][$vars['category']]['content'] : array();

  // If no category is selected or the category is empty or our special empty
  // category render a 'header' that will appear instead of the columns.
  if (empty($vars['category']) || empty($content) || $vars['category'] == 'root') {

    // Nothing to do since there is no preview
  }
  else {
    $titles = array_keys($content);
    natcasesort($titles);
    $col_size = count($titles) / $vars['column_count'];

    // Zero out the existing column data
    $count = 0;
    foreach ($titles as $title) {
      $which = floor($count++ / $col_size) + 1;
      $vars['columns'][$which] = '';
    }

    // Render the single preview if it's requested.
    if ($use_preview == PANOPOLY_ADD_PREVIEW_SINGLE) {
      $title = $vars['preview_single_title'];
      $legend_title = !empty($title) ? $title : t('Select a widget to show its preview');
      $add_content_link = !empty($title) ? _panopoly_magic_render_add_content_link($vars, $content[$title], $title) : '';
      $preview = !empty($vars['preview_single']) ? $vars['preview_single'] : t('No Preview');
      $vars['columns'][0] = theme('panopoly_magic_preview', array(
        'title' => $legend_title,
        'add_link' => $add_content_link,
        'preview' => $preview,
      ));
    }

    // Read the column data with our preview functionality
    $count = 0;
    foreach ($titles as $title) {
      $which = floor($count++ / $col_size) + 1;
      $legend_title = $content[$title]['title'];
      $add_content_link = _panopoly_magic_render_add_content_link($vars, $content[$title], $title);
      $description = !empty($content[$title]['description']) && variable_get('panopoly_magic_pane_show_description', 1) ? $content[$title]['description'] : '';
      if ($use_preview == PANOPOLY_ADD_PREVIEW_SINGLE) {
        $vars['columns'][$which] .= theme('panopoly_magic_preview_link', array(
          'preview_link' => $legend_title,
          'add_link' => $add_content_link,
          'description' => $description,
        ));
      }
      else {
        $preview = !empty($content[$title]['preview']) ? $content[$title]['preview'] : t('No Preview');
        $vars['columns'][$which] .= theme('panopoly_magic_preview', array(
          'title' => $legend_title,
          'add_link' => $add_content_link,
          'preview' => $preview,
          'preview_subtype_name' => $content[$title]['subtype_name'],
          'description' => $description,
        ));
      }
    }
  }
}