function views_plugin_display::init
Same name in other branches
- 7.x-3.x plugins/views_plugin_display.inc \views_plugin_display::init()
File
-
plugins/
views_plugin_display.inc, line 41
Class
- views_plugin_display
- The default display plugin handler. Display plugins handle options and basic mechanisms for different output methods.
Code
function init(&$view, &$display, $options = NULL) {
$this->view =& $view;
$this->display =& $display;
// Make some modifications:
if (!isset($options)) {
$options = $display->display_options;
}
if ($this->is_default_display() && isset($options['defaults'])) {
unset($options['defaults']);
}
// Cache for unpack_options, but not if we are in the ui.
static $unpack_options = array();
if (empty($view->editing)) {
$cid = 'unpack_options:' . md5(serialize(array(
$this->options,
$options,
)));
if (empty($unpack_options[$cid])) {
$cache = views_cache_get($cid, TRUE);
if (!empty($cache->data)) {
$this->options = $cache->data;
}
else {
$this->unpack_options($this->options, $options);
views_cache_set($cid, $this->options, TRUE);
}
$unpack_options[$cid] = $this->options;
}
else {
$this->options = $unpack_options[$cid];
}
}
else {
$this->unpack_options($this->options, $options);
}
// Translate changed settings:
$items_per_page = $this->get_option('items_per_page');
$offset = $this->get_option('offset');
$use_pager = $this->get_option('use_pager');
$pager = $this->get_option('pager');
// Check if the pager options were already converted.
// The pager settings of a Views 2.x view specifying 10 items with an
// offset of 0 and no pager is the same as of a Views 3.x view with
// default settings. In this case, the only way to determine which case we
// are dealing with is checking the API version but that's only available
// for exported Views as it's not stored in the database.
// If you would like to change this code, really take care that you thought
// of every possibility.
// @TODO: Provide a way to convert the database views as well.
if (!empty($items_per_page) && $items_per_page != 10 || !empty($offset) || !empty($use_pager) || !empty($view->api_version) && $view->api_version == 2) {
// Find out the right pager type.
// If the view "use pager" it's a normal/full pager.
if ($use_pager) {
$type = 'full';
}
else {
$type = $items_per_page ? 'some' : 'none';
}
// Setup the pager options.
$pager = array(
'type' => $type,
'options' => array(
'offset' => intval($offset),
),
);
if ($items_per_page) {
$pager['options']['items_per_page'] = $items_per_page;
}
// Setup the pager element.
if ($id = $this->get_option('pager_element')) {
$pager['options']['id'] = $id;
}
// Unset the previous options
// After edit and save the view they will be erased
$this->set_option('items_per_page', NULL);
$this->set_option('offset', NULL);
$this->set_option('use_pager', NULL);
$this->set_option('pager', $pager);
}
// Plugable headers, footer and empty texts are
// not compatible with previous version of views
// This code converts old values into a configured handler for each area
foreach (array(
'header',
'footer',
'empty',
) as $area) {
$converted = FALSE;
if (isset($this->options[$area]) && !is_array($this->options[$area])) {
if (!empty($this->options[$area])) {
$content = $this->get_option($area);
if (!empty($content) && !is_array($content)) {
$format = $this->get_option($area . '_format');
$options = array(
'id' => 'area',
'table' => 'views',
'field' => 'area',
'label' => '',
'relationship' => 'none',
'group_type' => 'group',
'content' => $content,
'format' => !empty($format) ? $format : variable_get('filter_default_format', 1),
);
if ($area != 'empty' && ($empty = $this->get_option($area . '_empty'))) {
$options['empty'] = $empty;
}
$this->set_option($area, array(
'text' => $options,
));
$converted = TRUE;
}
}
// Ensure that options are at least an empty array
if (!$converted) {
$this->set_option($area, array());
}
}
}
// Convert distinct setting from display to query settings.
$distinct = $this->get_option('distinct');
if (!empty($distinct)) {
$query_settings = $this->get_option('query');
$query_settings['options']['distinct'] = $distinct;
$this->set_option('query', $query_settings);
// Clear the values
$this->set_option('distinct', NULL);
}
// Convert filter groups.
$filter_groups = $this->get_option('filter_groups');
// Only convert if it wasn't converted yet, which is the case if there is a 0 group.
if (isset($filter_groups['groups'][0])) {
// Update filter groups.
$filter_groups['groups'] = views_array_key_plus($filter_groups['groups']);
$this->set_option('filter_groups', $filter_groups);
// Update the filter group on each filter.
$filters = $this->get_option('filters');
foreach ($filters as &$filter) {
$filter['group']++;
}
$this->set_option('filters', $filters);
}
}