function panels_add_content in Panels 6.2
Same name and namespace in other branches
- 5.2 includes/display_edit.inc \panels_add_content()
Related topics
1 call to panels_add_content()
- panels_ajax_add_pane_choose in includes/
display-edit.inc - Entry point for AJAX: 'Add Content' modal form, from which the user selects the type of pane to add.
File
- includes/
display-edit.inc, line 352
Code
function panels_add_content($cache, $panel_id) {
$did = $cache->display->did;
if (!isset($cache->content_types)) {
$cache->content_types = panels_get_available_content_types();
}
$weights = array(
t('Contributed blocks') => 0,
);
$categories = array();
$titles = array();
foreach ($cache->content_types as $type_name => $subtypes) {
if (is_array($subtypes)) {
$content_type = panels_get_content_type($type_name);
foreach ($subtypes as $subtype_name => $subtype_info) {
$title = filter_xss_admin($subtype_info['title']);
$description = isset($subtype_info['description']) ? $subtype_info['description'] : $title;
$icon = '';
if (isset($subtype_info['icon'])) {
$icon = $subtype_info['icon'];
if (isset($subtype_info['path']) && file_exists($subtype_info['path'] . '/' . $icon)) {
$path = $subtype_info['path'];
}
else {
if (isset($content_type['path']) && file_exists($content_type['path'] . '/' . $icon)) {
$path = $content_type['path'];
}
else {
if (file_exists(panels_get_path("content_types/{$type_name}") . '/' . $icon)) {
$path = panels_get_path("content_types/{$type_name}");
}
}
}
}
if (empty($icon)) {
$icon = 'no-icon.png';
$path = panels_get_path('images');
}
if (isset($subtype_info['category'])) {
if (is_array($subtype_info['category'])) {
list($category, $weight) = $subtype_info['category'];
$weights[$category] = $weight;
}
else {
$category = $subtype_info['category'];
if (!isset($weights['category'])) {
$weights[$category] = 0;
}
}
}
else {
$category = t('Contrib blocks');
}
$output = '<div class="content-type-button clear-block">';
$link_image = theme('image', $path . '/' . $icon, $description, $description);
$url = "panels/ajax/add-pane-config/{$did}/{$panel_id}/{$type_name}/{$subtype_name}";
$output .= panels_ajax_text_button($link_image, $url, $description, 'panels-modal-add-config');
$output .= '<div>' . panels_ajax_text_button($title, $url, $description, 'panels-modal-add-config') . '</div>';
$output .= '</div>';
if (!isset($categories[$category])) {
$categories[$category] = array();
$titles[$category] = array();
}
$categories[$category][] = $output;
$titles[$category][] = $title;
}
}
}
if (!$categories) {
$output = t('There are no content types you may add to this display.');
}
else {
asort($weights);
$output = '';
$columns = 3;
foreach (range(1, $columns) as $column) {
$col[$column] = '';
$size[$column] = 0;
}
foreach ($weights as $category => $weight) {
$which = 1;
// default;
$count = count($titles[$category]) + 3;
// add 3 to account for title.
// Determine which column to use by seeing which column has the most
// free space. This algorithm favors left.
foreach (range($columns, 2) as $column) {
if ($size[$column - 1] - $size[$column] > $count / 2 || $size[$column - 1] > 0 && $size[$column] == 0) {
$which = $column;
break;
}
}
$col[$which] .= '<div class="panels-section">';
$col[$which] .= '<h3 class="panels-section-title">' . $category . '</h3>';
$col[$which] .= '<div class="panels-section-decorator"></div>';
$col[$which] .= '<div class="panels-section-content">';
if (is_array($titles[$category])) {
natcasesort($titles[$category]);
foreach ($titles[$category] as $id => $title) {
$col[$which] .= $categories[$category][$id];
}
}
$col[$which] .= '</div>';
$col[$which] .= '</div>';
$size[$which] += $count;
}
foreach ($col as $column) {
$output .= '<div class="panels-section-column">' . $column . '</div>';
}
}
return $output;
}