1 views.block.inc | ViewsBlock::form(&$form, &$form_state) |
Build the settings form for editing this block.
Overrides Block::form
File
- core/
modules/ views/ includes/ views.block.inc, line 257
Class
- ViewsBlock
- Displays a view listing as a block, with overriding options.
Code
function form(&$form, &$form_state) {
parent::form($form, $form_state);
list($name, $display_id) = explode('-', $this->delta);
$view = views_get_view($name);
if (empty($view)) {
$form['markup'] = array('#markup' => t('Broken/missing/deleted view.'));
return;
}
$view->set_display($display_id);
// If it couldn't set the display and we got the default display instead,
// fail.
if ($view->current_display == 'default') {
$form['markup'] = array('#markup' => t('Broken/missing/deleted view display.'));
return;
}
// Get the list of settings that are allowed to be overridden.
$allow = $view->display_handler->get_option('allow');
// Provide defaults for everything in order to prevent warnings.
$this->setDefaultsFromView($view);
$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($this->settings['arguments'][$id]) ? $this->settings['arguments'][$id] : '',
'#title' => check_plain($argument['label']),
);
}
}
if ($allow['link_to_view']) {
$form['link_to_view'] = array(
'#type' => 'checkbox',
'#default_value' => isset($this->settings['link_to_view']) ? $this->settings['link_to_view'] : $view->display_handler->get_option('link_to_view'),
'#title' => t('Link title to view page path'),
'#states' => array(
'visible' => array(
'form.layout-block-configure-form :input[name="title_display"]' => array('!value' => LAYOUT_TITLE_NONE),
),
),
);
}
if ($allow['more_link']) {
$form['more_link'] = array(
'#type' => 'checkbox',
'#default_value' => isset($this->settings['more_link']) ? $this->settings['more_link'] : $view->display_handler->get_option('use_more'),
'#description' => t('The text of this link will be "@more". The text can be modified within the view configuration.', array('@more' => $view->display_handler->use_more_text())),
'#title' => t('Provide a "more" link.'),
);
}
if ($allow['path_override']) {
$form['path_override'] = array(
'#type' => 'checkbox',
'#default_value' => $this->settings['path_override'],
'#title' => t('Override path'),
'#description' => t('Use a different path for the more link, pager, and other links.')
);
$form['path'] = array(
'#type' => 'textfield',
'#default_value' => isset($this->settings['path']) ? $this->settings['path'] : $view->get_path(),
'#title' => t('Override path'),
'#size' => 30, '#states' => array(
'visible' => array(
':input[name="path_override"]' => array('checked' => TRUE),
),
),
);
}
$view->init_style();
if (empty($this->settings['exposed'])) {
$this->settings['exposed'] = array();
}
if ($allow['exposed_form']) {
// If the exposed form is part of block 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($this->settings['exposed']);
$exposed_form_state['exposed_form_plugin'] = $view->display_handler->get_plugin('exposed_form');
$view->init_handlers();
$exposed_form = array();
$exposed_form = views_exposed_form($exposed_form, $exposed_form_state);
foreach ($exposed_form['#info'] as $id => $info) {
$form['exposed'][$id] = array(
'#type' => 'item',
'#id' => 'views-exposed-block',
);
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($this->settings['exposed'][$info['operator']]) ? $this->settings['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($this->settings['exposed'][$info['value']]) ? $this->settings['exposed'][$info['value']] : '';
}
}
// The exposed sort stuff doesn't fall into $exposed_form['#info'] so we
// have to handle it separately.
if (isset($exposed_form['sort_by'])) {
$form['exposed']['sort_by'] = $exposed_form['sort_by'];
}
if (isset($exposed_form['sort_order'])) {
$form['exposed']['sort_order'] = $exposed_form['sort_order'];
}
if (!empty($form['exposed'])) {
$form['exposed'] += array(
'#title' => t('Filter options'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
}
if ($allow['fields_override'] && $view->style_plugin->uses_fields()) {
$form['fields_override'] = array(
'#type' => 'fieldset',
'#title' => t('Fields to display'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
foreach ($view->display_handler->get_handlers('field') as $field => $handler) {
$title = $handler->ui_name();
if ($handler->options['label']) {
$title .= ' (' . check_plain($handler->options['label']) . ')';
}
$form['fields_override'][$field] = array(
'#type' => 'checkbox',
'#title' => $title,
'#default_value' => isset($this->settings['fields_override'][$field]) ? $this->settings['fields_override'][$field] : !$handler->options['exclude'],
);
}
}
if ($allow['use_pager']) {
$form['pager']['use_pager'] = array(
'#type' => 'checkbox',
'#title' => t('Use pager'),
'#default_value' => $this->settings['use_pager'],
);
$form['pager']['pager_id'] = array(
'#type' => 'number',
'#default_value' => $this->settings['pager_id'],
'#title' => t('Pager ID'),
'#step' => 1,
'#min' => 0,
'#max' => 999,
'#states' => array(
'visible' => array(
'input[name="use_pager"]' => array('checked' => TRUE),
),
),
);
}
if ($allow['items_per_page']) {
$form['pager']['items_per_page'] = array(
'#type' => 'number',
'#default_value' => $this->settings['items_per_page'],
'#title' => t('Number of items'),
'#min' => 0,
'#max' => 1000,
'#description' => t('Select the number of items to display, or 0 to display all results.'),
);
}
if ($allow['offset']) {
$form['pager']['offset'] = array(
'#type' => 'textfield',
'#default_value' => $this->settings['offset'],
'#title' => t('Offset'),
'#size' => 4,
'#description' => t('Enter the number of items to skip; enter 0 to skip no items.'),
);
}
if (!empty($form['pager'])) {
$form['pager'] += array(
'#type' => 'fieldset',
'#title' => t('Pager options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => FALSE,
);
}
}