views.inc in Patterns 6.2
File
components/views.inc
View source
<?php
function views_patterns($op, $id = null, &$data = null) {
switch ($op) {
case 'tags':
return array(
'view',
);
break;
case 'actions':
return array();
break;
case 'prepare':
views_include('view');
if ($details = $data['details']) {
$data = array_merge($data, $details);
}
$data['tag'] = $data['tags'];
if (!($view = views_get_view($data['name']))) {
$view = views_new_view();
$view->name = $data['name'];
}
$view
->init_display();
$attributes = array(
'description' => 'description',
'tag' => 'tag',
'base' => 'base_table',
);
foreach ($attributes as $data_key => $key) {
if (!($value = $data[$data_key])) {
continue;
}
if (is_array($value)) {
$value = array_merge((array) $view->{$key}, $value);
}
$view->{$key} = $value;
}
foreach ($data['display'] as &$display_data) {
foreach (explode(' ', 'section item options filters sorts') as $key) {
if (!$display_data[$key]) {
$display_data[$key] = array();
}
}
$display_id = $display_data['display_id'] ? $display_data['display_id'] : $display_data['name'];
$display_plugin = $display_id;
if ($pos = strpos($display_plugin, "_")) {
$display_plugin = substr($display_plugin, 0, $pos);
}
$default_title = $display_id == 'default' ? 'Defaults' : ucfirst($display_plugin);
$display_title = $display_data['display_title'] ? $display_data['display_title'] : $default_title;
$display_title = $display_data['options']['title'] ? $display_data['options']['title'] : $display_title;
if ($display = $view->display[$display_id]) {
$handler = $display->handler;
$display->display_title = $display_title;
}
else {
$handler = $view
->new_display($display_plugin, $display_title, $display_id);
}
foreach ($display_data['section'] as $section) {
$display_data['options'][$section['section']] = $section['value'];
}
foreach ($display_data['options'] as $key => $value) {
$handler
->override_option($key, $value);
}
foreach ($display_data['item'] as &$item) {
list($table, $field) = explode('.', $item['name']);
$item['data'] = array_merge((array) $item['data'], array(
'table' => $table,
'field' => $field,
));
$collection_name = $item['type'] . 's';
$display_data[$collection_name][$field] = $item['data'];
}
foreach (explode(' ', 'filters sorts relationships arguments fields') as $key) {
if ($option = $display_data[$key]) {
$handler
->override_option($key, $option);
}
}
}
$view
->save();
break;
case 'pre-validate':
break;
case 'form_id':
return array();
break;
case 'validate':
break;
case 'build':
return null;
break;
case 'params':
break;
case 'cleanup':
break;
case 'identifier':
break;
}
}