function views_plugin_ds_entity_view::options_form in Display Suite 7
Same name and namespace in other branches
- 7.2 views/views_plugin_ds_entity_view.inc \views_plugin_ds_entity_view::options_form()
Provide a form for setting options.
Overrides views_plugin_row::options_form
File
- views/
views_plugin_ds_entity_view.inc, line 90 - Provides the Display suite views entity style plugin.
Class
- views_plugin_ds_entity_view
- Plugin which defines the view mode on the resulting entity object.
Code
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$view_mode_options = array();
$entity_type = $this->view->base_table;
// In case we're working with users or managed files, change the entity type variable.
if ($entity_type == 'users') {
$entity_type = 'user';
}
if ($entity_type == 'file_managed') {
$entity_type = 'file';
}
$entity_view_modes = ds_entity_view_modes($entity_type);
foreach ($entity_view_modes as $key => $view_mode) {
$view_mode_options[$key] = $view_mode['label'];
}
// Default view mode & load comments.
$form['default_fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Default view mode'),
'#collapsible' => TRUE,
'#collapsed' => $this->options['advanced'],
);
$form['default_fieldset']['view_mode'] = array(
'#type' => 'select',
'#default_value' => $this->options['view_mode'],
'#options' => $view_mode_options,
'#description' => t('Select the default view mode for this view.'),
);
if ($entity_type == 'node') {
$form['default_fieldset']['load_comments'] = array(
'#title' => t('Comments'),
'#type' => 'checkbox',
'#description' => t('Load comments for every node to display.'),
'#default_value' => isset($this->options['load_comments']) ? $this->options['load_comments'] : FALSE,
'#access' => module_exists('comment'),
);
}
// Changing view modes.
$form['alternating_fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Alternating view mode'),
'#collapsible' => TRUE,
'#collapsed' => !$this->options['alternating'],
);
$form['alternating_fieldset']['alternating'] = array(
'#type' => 'checkbox',
'#title' => t('Use the changing view mode selector'),
'#default_value' => $this->options['alternating'],
);
$form['alternating_fieldset']['allpages'] = array(
'#type' => 'checkbox',
'#title' => t('Use this configuration on every page. Otherwhise the default view mode is used as soon you browse away from the first page of this view.'),
'#default_value' => isset($this->options['alternating_fieldset']['allpages']) ? $this->options['alternating_fieldset']['allpages'] : FALSE,
);
$limit = $this->view->display_handler
->get_option('items_per_page');
$pager = $this->view->display_handler
->get_plugin('pager');
$limit = isset($pager->options['items_per_page']) ? $pager->options['items_per_page'] : 0;
if ($limit == 0 || $limit > 20) {
$form['alternating_fieldset']['disabled'] = array(
'#markup' => t('This option is disabled because you have unlimited items or listing more than 20 items.'),
);
$form['alternating_fieldset']['alternating']['#disabled'] = TRUE;
$form['alternating_fieldset']['allpages']['#disabled'] = TRUE;
}
else {
$i = 1;
$a = 0;
while ($limit != 0) {
$form['alternating_fieldset']['item_' . $a] = array(
'#title' => t('Item @nr', array(
'@nr' => $i,
)),
'#type' => 'select',
'#default_value' => isset($this->options['alternating_fieldset']['item_' . $a]) ? $this->options['alternating_fieldset']['item_' . $a] : 'teaser',
'#options' => $view_mode_options,
);
$limit--;
$a++;
$i++;
}
}
// Grouping rows.
$sorts = $this->view->display_handler
->get_option('sorts');
$groupable = !empty($sorts) && $this->options['grouping'];
$form['grouping_fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Group data'),
'#collapsible' => TRUE,
'#collapsed' => !$groupable,
);
$form['grouping_fieldset']['grouping'] = array(
'#type' => 'checkbox',
'#title' => t('Group data on a field. The value of this field will be displayed too.'),
'#default_value' => $groupable,
);
if (!empty($sorts)) {
$sort_options = array();
foreach ($sorts as $key => $sort) {
$sort_name = drupal_ucfirst($sort['field']);
$sort_options[$sort['table'] . '|' . $sort['field']] = $sort_name;
}
$form['grouping_fieldset']['group_field'] = array(
'#type' => 'select',
'#options' => $sort_options,
'#default_value' => isset($this->options['grouping_fieldset']['group_field']) ? $this->options['grouping_fieldset']['group_field'] : '',
);
$form['grouping_fieldset']['group_field_function'] = array(
'#type' => 'textfield',
'#title' => 'Heading function',
'#description' => check_plain(t('The value of the field can be in a very raw format (eg, date created). Enter a custom function which you can use to format that value. The value and the object will be passed into that function eg. custom_function($raw_value, $object);')),
'#default_value' => isset($this->options['grouping_fieldset']['group_field_function']) ? $this->options['grouping_fieldset']['group_field_function'] : '',
);
}
else {
$form['grouping_fieldset']['grouping']['#disabled'] = TRUE;
$form['grouping_fieldset']['grouping']['#description'] = t('Grouping is disabled because you do not have any sort fields.');
}
// Advanced function.
$form['advanced_fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced view mode'),
'#collapsible' => TRUE,
'#collapsed' => !$this->options['advanced'],
);
$form['advanced_fieldset']['advanced'] = array(
'#type' => 'checkbox',
'#title' => t('Use the advanced view mode selector'),
'#description' => t('This gives you the opportunity to have full control of a list for really advanced features.<br /> There is no UI for this, you need to create a function named like this: ds_views_row_adv_@VIEWSNAME($entity, $view_mode, $load_comments).<br />See <a href="http://drupal.org/node/697320#ds_views_row_adv_VIEWSNAME">http://drupal.org/node/697320#ds_views_row_adv_VIEWSNAME</a> for an example.', array(
'@VIEWSNAME' => $this->view->name,
)),
'#default_value' => $this->options['advanced'],
);
}