View source
<?php
$plugin = array(
'single' => TRUE,
'title' => t('Admin - Content types'),
'defaults' => array(
'types' => NULL,
),
'icon' => 'cog.png',
'description' => t('Provides links to manage content types.'),
'category' => t('Dashboard'),
'edit text' => t('Configure'),
);
function total_control_node_types_content_type_admin_title($subtype = NULL, $conf = NULL, $context = NULL) {
return t('Manage Content types');
}
function total_control_node_types_content_type_admin_info($subtype = NULL, $conf = NULL, $context = NULL) {
$block = new stdClass();
$block->title = t('Provides links to manage content types.');
return $block;
}
function total_control_node_types_content_type_render($subtype, $conf, $panel_args, &$context) {
$types = node_type_get_types();
$access = user_access('administer content types');
$options = array(
'query' => array(
'destination' => 'admin/dashboard',
),
);
$header = array(
array(
'data' => t('Content type'),
),
array(
'data' => t('Operations'),
'colspan' => 3,
),
);
$rows = array();
foreach ($types as $type => $object) {
if (!array_key_exists($type, $conf['types']) || (isset($conf['types']) && $conf['types'][$type]) == $type) {
if ($access) {
$type_url_str = str_replace('_', '-', $object->type);
$rows[] = array(
'data' => array(
t($object->name),
l(t('Configure'), 'admin/structure/types/manage/' . $type_url_str, $options),
l(t('Manage fields'), 'admin/structure/types/manage/' . $type_url_str . '/fields', $options),
l(t('Manage display'), 'admin/structure/types/manage/' . $type_url_str . '/display', $options),
),
);
}
}
}
if (empty($rows)) {
$rows[] = array(
array(
'data' => t('There are no content types to display.'),
'colspan' => 4,
),
);
}
$link = '';
if (user_access('administer content types')) {
$link = l(t('Content type administration'), 'admin/structure/types');
}
$block = new stdClass();
$block->module = t('total_control');
$block->title = t('Manage Content types');
$block->content = theme('total_control_admin_table', array(
'header' => $header,
'rows' => $rows,
'link' => $link,
));
return $block;
}
function total_control_node_types_content_type_edit_form($form, &$form_state) {
$conf = $form_state['conf'];
$types = node_type_get_types();
$type_options = array();
$type_defaults = array();
if (isset($conf['types'])) {
$type_defaults = $conf['types'];
}
foreach ($types as $type => $object) {
$type_options[$type] = $object->name;
if (!array_key_exists($type, $type_defaults)) {
$type_defaults[$type] = $type;
}
}
$form['types'] = array(
'#type' => 'checkboxes',
'#title' => t('Include Create links for Content Types'),
'#options' => $type_options,
'#default_value' => $type_defaults,
);
return $form;
}
function total_control_node_types_content_type_edit_form_submit($form, &$form_state) {
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}