class views_merge_rows_plugin_display_extender in Views Merge Rows 7
The plugin that merges rows with the same content in the specified fields.
Hierarchy
- class \views_object
- class \views_plugin
Expanded class hierarchy of views_merge_rows_plugin_display_extender
1 string reference to 'views_merge_rows_plugin_display_extender'
- views_merge_rows_views_plugins in ./
views_merge_rows.views.inc - Implements hook_views_plugins().
File
- ./
views_merge_rows_plugin_display_extender.inc, line 12 - Contains the class to extend views display with rows merge functionality.
View source
class views_merge_rows_plugin_display_extender extends views_plugin_display_extender {
/**
* Provide a list of options for this plugin.
*/
public function options_definition_alter(&$options) {
$options['merge_rows'] = array(
'default' => FALSE,
'bool' => TRUE,
);
$options['field_config'] = array(
'default' => array(),
);
}
/**
* Returns configuration for row merging.
*
* Only returns the configuration for the fields present in the view.
* If a new field was added to the view, the default configuration for this
* field is returned.
*
* @return array
* Configuration for row merging.
*/
public function get_options() {
if ($this->display->display->handler
->uses_fields()) {
$options = array();
$options['merge_rows'] = $this->display
->get_option('merge_rows');
if (empty($options['merge_rows'])) {
$options['merge_rows'] = FALSE;
}
$options['field_config'] = array();
$field_config = $this->display
->get_option('field_config');
$fields = $this->display->display->handler
->get_option('fields');
foreach ($fields as $field => $info) {
if (isset($field_config[$field])) {
$options['field_config'][$field] = $field_config[$field];
}
else {
$options['field_config'][$field] = array(
'merge_option' => 'merge_unique',
'separator' => ', ',
);
}
}
}
else {
$options['merge_rows'] = FALSE;
$options['field_config'] = array();
}
return $options;
}
/**
* Provide a form to edit options for this plugin.
*/
protected function views_merge_rows_options_form(&$form, &$form_state) {
$options = $this
->get_options();
if ($this->display->display->handler
->use_pager()) {
$form['warning_markup'] = array(
'#markup' => '<div class="warning messages">' . t('It is highly recommended to disable pager if you merge rows.') . '</div>',
);
}
$form['#tree'] = TRUE;
$form['#theme'] = 'views_merge_rows_display_extender_plugin_table';
$form['#title'] .= t('Merge rows with the same content.');
$form['merge_rows'] = array(
'#type' => 'checkbox',
'#title' => t('Merge rows with the same content in the specified fields'),
'#default_value' => $options['merge_rows'],
);
// Create an array of allowed columns from the data we know:
$field_names = $this->display->display->handler
->get_field_labels();
foreach ($field_names as $field => $name) {
$safe = str_replace(array(
'][',
'_',
' ',
), '-', $field);
// Markup for the field name.
$form['field_config'][$field]['name'] = array(
'#markup' => $name,
);
// Select for merge options.
$form['field_config'][$field]['merge_option'] = array(
'#type' => 'select',
'#options' => array(
'merge_unique' => t('Merge unique values of this field'),
'merge' => t('Merge values of this field'),
'filter' => t('Use values of this field as a filter'),
'first_value' => t('Use the first value of this field'),
'count' => t('Count merged values of this field'),
'count_unique' => t('Count merged unique values of this field'),
),
'#default_value' => $options['field_config'][$field]['merge_option'],
);
$form['field_config'][$field]['separator'] = array(
'#id' => 'views-merge-rows-separator',
'#title' => t('Separator:'),
'#type' => 'textfield',
'#size' => 10,
'#default_value' => $options['field_config'][$field]['separator'],
'#dependency' => array(
'edit-options-field-config-' . $safe . '-merge-option' => array(
'merge',
'merge_unique',
),
),
);
}
}
/**
* Saves the row merge options.
*/
protected function views_merge_rows_options_form_submit(&$form, &$form_state) {
foreach ($form_state['values']['options'] as $option => $value) {
$this->display
->set_option($option, $value);
}
}
/**
* Provide the form to set the rows merge options.
*/
public function options_form(&$form, &$form_state) {
switch ($form_state['section']) {
case 'views_merge_rows':
$this
->views_merge_rows_options_form($form, $form_state);
break;
}
}
/**
* Saves the row merge options.
*/
public function options_submit(&$form, &$form_state) {
switch ($form_state['section']) {
case 'views_merge_rows':
$this
->views_merge_rows_options_form_submit($form, $form_state);
break;
}
}
/**
* Provide the default summary for options in the views UI.
*/
public function options_summary(&$categories, &$options) {
if ($this->display->display->handler
->uses_fields()) {
$configuration = $this
->get_options();
$options['views_merge_rows'] = array(
'category' => 'other',
'title' => t('Merge rows'),
'value' => $configuration['merge_rows'] ? t('Settings') : t('No'),
'desc' => t('Allow merging rows with the same content in the specified fields.'),
);
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
views_merge_rows_plugin_display_extender:: |
public | function | Returns configuration for row merging. | |
views_merge_rows_plugin_display_extender:: |
public | function |
Provide a list of options for this plugin. Overrides views_plugin_display_extender:: |
|
views_merge_rows_plugin_display_extender:: |
public | function |
Provide the form to set the rows merge options. Overrides views_plugin_display_extender:: |
|
views_merge_rows_plugin_display_extender:: |
public | function |
Saves the row merge options. Overrides views_plugin_display_extender:: |
|
views_merge_rows_plugin_display_extender:: |
public | function |
Provide the default summary for options in the views UI. Overrides views_plugin_display_extender:: |
|
views_merge_rows_plugin_display_extender:: |
protected | function | Provide a form to edit options for this plugin. | |
views_merge_rows_plugin_display_extender:: |
protected | function | Saves the row merge options. | |
views_object:: |
public | property | Handler's definition. | |
views_object:: |
public | property | Except for displays, options for the object will be held here. | 1 |
views_object:: |
function | Collect this handler's option definition and alter them, ready for use. | ||
views_object:: |
public | function | Views handlers use a special construct function. | 4 |
views_object:: |
public | function | Destructor. | 2 |
views_object:: |
public | function | 1 | |
views_object:: |
public | function | ||
views_object:: |
public | function | Always exports the option, regardless of the default value. | |
views_object:: |
public | function | Set default options on this object. | 1 |
views_object:: |
public | function | Information about options for all kinds of purposes will be held here. | 13 |
views_object:: |
public | function | Set default options. | |
views_object:: |
public | function | Let the handler know what its full definition is. | |
views_object:: |
public | function | Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away. | |
views_object:: |
public | function | Unpack a single option definition. | |
views_object:: |
public | function | Unpacks each handler to store translatable texts. | |
views_object:: |
public | function | ||
views_plugin:: |
public | property | The current used views display. | |
views_plugin:: |
public | property | The plugin name of this plugin, for example table or full. | |
views_plugin:: |
public | property | The plugin type of this plugin, for example style or query. | |
views_plugin:: |
public | property |
The top object of a view. Overrides views_object:: |
1 |
views_plugin:: |
public | function | Provide a list of additional theme functions for the theme info page. | |
views_plugin:: |
public | function | Return the human readable name of the display. | |
views_plugin:: |
public | function | Returns the summary of the settings in the display. | 8 |
views_plugin:: |
public | function | Provide a full list of possible theme templates used by this style. | |
views_plugin:: |
public | function | Validate that the plugin is correct and can be saved. | 3 |
views_plugin_display_extender:: |
public | function | Static member function to list which sections are defaultable and what items each section contains. | |
views_plugin_display_extender:: |
public | function | ||
views_plugin_display_extender:: |
public | function |
Validate the options form. Overrides views_plugin:: |
|
views_plugin_display_extender:: |
public | function | Set up any variables on the view prior to execution. | |
views_plugin_display_extender:: |
public | function |
Inject anything into the query that the display_extender handler needs. Overrides views_plugin:: |