function views_content_views_panes_content_type_edit_form in Chaos Tool Suite (ctools) 6
Same name and namespace in other branches
- 7 views_content/plugins/content_types/views_panes.inc \views_content_views_panes_content_type_edit_form()
Returns an edit form for a block.
File
- views_content/
plugins/ content_types/ views_panes.inc, line 330 - Content type plugin to allow Views to be exposed as a display type, leaving most of the configuration on the view.
Code
function views_content_views_panes_content_type_edit_form(&$form, &$form_state) {
$conf = $form_state['conf'];
$contexts = $form_state['contexts'];
// This allows older content to continue to work, where we used to embed
// the display directly.
list($name, $display_id) = explode('-', $form_state['subtype_name']);
$view = views_get_view($name);
if (empty($view)) {
$form['markup'] = array(
'#value' => t('Broken/missing/deleted view.'),
);
return;
}
$view
->set_display($display_id);
$allow = $view->display_handler
->get_option('allow');
// Provide defaults for everything in order to prevent warnings.
if (empty($conf)) {
$conf['link_to_view'] = $view->display_handler
->get_option('link_to_view');
$conf['more_link'] = $view->display_handler
->get_option('more_link');
$conf['feed_icons'] = FALSE;
$conf['use_pager'] = $view->display_handler
->get_option('use_pager');
$conf['pager_id'] = $view->display_handler
->get_option('element_id');
$conf['items_per_page'] = $view->display_handler
->get_option('items_per_page');
$conf['offset'] = $view->display_handler
->get_option('offset');
$conf['path_override'] = FALSE;
$conf['path'] = $view
->get_path();
$conf['fields_override'] = $view->display_handler
->get_option('fields_override');
}
$form['arguments']['#tree'] = TRUE;
foreach ($view->display_handler
->get_argument_input() as $id => $argument) {
if ($argument['type'] == 'user') {
$form['arguments'][$id] = array(
'#type' => 'textfield',
'#default_value' => isset($conf['arguments'][$id]) ? $conf['arguments'][$id] : '',
'#title' => $argument['label'],
);
}
}
if ($allow['link_to_view']) {
$form['link_to_view'] = array(
'#type' => 'checkbox',
'#default_value' => isset($conf['link_to_view']) ? $conf['link_to_view'] : $view->display_handler
->get_option('link_to_view'),
'#title' => t('Link title to page'),
);
}
if ($allow['more_link']) {
$form['more_link'] = array(
'#type' => 'checkbox',
'#default_value' => isset($conf['more_link']) ? $conf['more_link'] : $view->display_handler
->get_option('use_more'),
'#description' => t('The text of this link will be "@more". This setting can only be modified on the View configuration.', array(
'@more' => $view->display_handler
->use_more_text(),
)),
'#title' => t('Provide a "more" link.'),
);
}
if (!empty($allow['feed_icons'])) {
$form['feed_icons'] = array(
'#type' => 'checkbox',
'#default_value' => !empty($conf['feed_icons']),
'#title' => t('Display feed icons'),
);
}
$view
->init_style();
if ($allow['fields_override'] && $view->style_plugin
->uses_fields()) {
$form['fields_override'] = array(
'#type' => 'fieldset',
'#title' => 'Fields to display',
'#collapsible' => TRUE,
'#tree' => TRUE,
);
foreach ($view->display_handler
->get_handlers('field') as $field => $handler) {
$title = $handler
->ui_name();
if ($handler->options['label']) {
$title .= ' (' . $handler->options['label'] . ')';
}
$form['fields_override'][$field] = array(
'#type' => 'checkbox',
'#title' => $title,
'#default_value' => isset($conf['fields_override'][$field]) ? $conf['fields_override'][$field] : TRUE,
);
}
}
ctools_include('dependent');
if ($allow['use_pager']) {
$form['use_pager'] = array(
'#type' => 'checkbox',
'#title' => t('Use pager'),
'#default_value' => isset($conf['use_pager']) ? $conf['use_pager'] : $view->display_handler
->get_option('use_pager'),
'#id' => 'use-pager-checkbox',
'#prefix' => '<div class="container-inline">',
);
$form['pager_id'] = array(
'#type' => 'textfield',
'#default_value' => isset($conf['pager_id']) ? $conf['pager_id'] : $view->display_handler
->get_option('element_id'),
'#title' => t('Pager ID'),
'#size' => 4,
'#id' => 'use-pager-textfield',
'#process' => array(
'ctools_dependent_process',
),
'#dependency' => array(
'use-pager-checkbox' => array(
1,
),
),
'#suffix' => '</div>',
);
}
if ($allow['items_per_page']) {
$form['items_per_page'] = array(
'#type' => 'textfield',
'#default_value' => isset($conf['items_per_page']) ? $conf['items_per_page'] : $view->display_handler
->get_option('items_per_page'),
'#title' => t('Num items'),
'#size' => 4,
'#description' => t('Select the number of items to display, or 0 to display all results.'),
);
}
if ($allow['offset']) {
$form['offset'] = array(
'#type' => 'textfield',
'#default_value' => isset($conf['offset']) ? $conf['offset'] : $view->display_handler
->get_option('offset'),
'#title' => t('Offset'),
'#size' => 4,
'#description' => t('Enter the number of items to skip; enter 0 to skip no items.'),
);
}
if ($allow['path_override']) {
$form['path'] = array(
'#type' => 'textfield',
'#default_value' => isset($conf['path']) ? $conf['path'] : $view
->get_path(),
'#title' => t('Override path'),
'#size' => 30,
'#description' => t('If this is set, override the View URL path; this can sometimes be useful to set to the panel URL.'),
);
if (!empty($contexts)) {
$form['path']['#description'] .= ' ' . t('You may use substitutions in this path.');
// Add js for collapsible fieldsets manually
drupal_add_js('misc/collapse.js');
// We have to create a manual fieldset because fieldsets do not support IDs.
// Use 'hidden' instead of 'markup' so that the process will run.
$form['contexts_prefix'] = array(
'#type' => 'hidden',
'#id' => 'edit-path-substitutions',
'#prefix' => '<div><fieldset id="edit-path-substitutions" class="collapsed collapsible"><legend>' . t('Substitutions') . '</legend>',
);
$rows = array();
foreach ($contexts as $context) {
foreach (ctools_context_get_converters('%' . check_plain($context->keyword) . ':', $context) as $keyword => $title) {
$rows[] = array(
check_plain($keyword),
t('@identifier: @title', array(
'@title' => $title,
'@identifier' => $context->identifier,
)),
);
}
}
$header = array(
t('Keyword'),
t('Value'),
);
$form['contexts']['context'] = array(
'#value' => theme('table', $header, $rows),
);
$form['contexts_suffix'] = array(
'#value' => '</fieldset></div>',
);
}
}
if (empty($conf['exposed'])) {
$conf['exposed'] = array();
}
if ($allow['exposed_form']) {
// If the exposed form is part of pane configuration, get the exposed
// form re-tool it for our use.
$exposed_form_state = array(
'view' => &$view,
'display' => &$view->display[$display_id],
);
$view
->set_exposed_input($conf['exposed']);
if (version_compare(views_api_version(), '3', '>=')) {
$exposed_form_state['exposed_form_plugin'] = $view->display_handler
->get_plugin('exposed_form');
}
$view
->init_handlers();
$exposed_form = views_exposed_form($exposed_form_state);
$form['exposed'] = array(
'#tree' => TRUE,
);
foreach ($exposed_form['#info'] as $id => $info) {
$form['exposed'][$id] = array(
'#type' => 'item',
'#id' => 'views-exposed-pane',
);
if (!empty($info['label'])) {
$form['exposed'][$id]['#title'] = $info['label'];
}
if (!empty($info['operator']) && !empty($exposed_form[$info['operator']])) {
$form['exposed'][$id][$info['operator']] = $exposed_form[$info['operator']];
$form['exposed'][$id][$info['operator']]['#parents'] = array(
'exposed',
$info['operator'],
);
$form['exposed'][$id][$info['operator']]['#default_value'] = isset($conf['exposed'][$info['operator']]) ? $conf['exposed'][$info['operator']] : '';
}
$form['exposed'][$id][$info['value']] = $exposed_form[$info['value']];
$form['exposed'][$id][$info['value']]['#parents'] = array(
'exposed',
$info['value'],
);
$form['exposed'][$id][$info['value']]['#default_value'] = isset($conf['exposed'][$info['value']]) ? $conf['exposed'][$info['value']] : '';
}
}
}