5 * Contains the CTools Export UI integration code.
7 * Note that this is only a partial integration.
11 * CTools Export UI class handler for Views UI.
13 class views_ui
extends ctools_export_ui
{
15 function init($plugin) {
16 // We modify the plugin info here so that we take the defaults and
17 // twiddle, rather than completely override them.
19 // Reset the edit path to match what we're really using.
20 $plugin['menu']['items']['edit']['path'] = 'view/%ctools_export_ui/edit';
21 $plugin['menu']['items']['clone']['path'] = 'view/%ctools_export_ui/clone';
22 $plugin['menu']['items']['clone']['type'] = MENU_VISIBLE_IN_BREADCRUMB
;
23 $plugin['menu']['items']['export']['path'] = 'view/%ctools_export_ui/export';
24 $plugin['menu']['items']['export']['type'] = MENU_VISIBLE_IN_BREADCRUMB
;
25 $plugin['menu']['items']['enable']['path'] = 'view/%ctools_export_ui/enable';
26 $plugin['menu']['items']['disable']['path'] = 'view/%ctools_export_ui/disable';
27 $plugin['menu']['items']['delete']['path'] = 'view/%ctools_export_ui/delete';
28 $plugin['menu']['items']['delete']['type'] = MENU_VISIBLE_IN_BREADCRUMB
;
29 $plugin['menu']['items']['revert']['path'] = 'view/%ctools_export_ui/revert';
30 $plugin['menu']['items']['revert']['type'] = MENU_VISIBLE_IN_BREADCRUMB
;
32 $prefix_count = count(explode('/', $plugin['menu']['menu prefix']));
33 $plugin['menu']['items']['add-template'] = array(
34 'path' => 'template/%/add',
35 'title' => 'Add from template',
36 'page callback' => 'ctools_export_ui_switcher_page',
37 'page arguments' => array($plugin['name'], 'add_template', $prefix_count +
2),
38 'load arguments' => array($plugin['name']),
39 'access callback' => 'ctools_export_ui_task_access',
40 'access arguments' => array($plugin['name'], 'add_template', $prefix_count +
2),
41 'type' => MENU_CALLBACK
,
44 return parent
::init($plugin);
47 function hook_menu(&$items) {
48 // We are using our own 'edit' still, rather than having edit on this
49 // object (maybe in the future) so unset the edit callbacks:
51 // Store this so we can put them back as sometimes they're needed
53 $stored_items = $this->plugin
['menu']['items'];
54 // We leave these to make sure the operations still exist in the plugin so
55 // that the path finder.
56 unset($this->plugin
['menu']['items']['edit']);
57 unset($this->plugin
['menu']['items']['add']);
58 unset($this->plugin
['menu']['items']['import']);
59 unset($this->plugin
['menu']['items']['edit callback']);
61 parent
::hook_menu($items);
63 $this->plugin
['menu']['items'] = $stored_items;
66 function load_item($item_name) {
67 return views_ui_cache_load($item_name);
70 function list_form(&$form, &$form_state) {
71 $row_class = 'container-inline';
72 if (!variable_get('views_ui_show_listing_filters', FALSE)) {
73 $row_class .= " element-invisible";
76 views_include('admin');
78 parent
::list_form($form, $form_state);
80 // ctools only has two rows. We want four.
81 // That's why we create our own structure.
82 $form['bottom row']['submit']['#attributes']['class'][] = 'js-hide';
83 $form['first row'] = array(
84 '#prefix' => '<div class="' . $row_class . ' ctools-export-ui-row ctools-export-ui-first-row clearfix">',
85 '#suffix' => '</div>',
86 'search' => $form['top row']['search'],
87 'submit' => $form['bottom row']['submit'],
88 'reset' => $form['bottom row']['reset'],
90 $form['second row'] = array(
91 '#prefix' => '<div class="' . $row_class . ' ctools-export-ui-row ctools-export-ui-second-row clearfix">',
92 '#suffix' => '</div>',
93 'storage' => $form['top row']['storage'],
94 'disabled' => $form['top row']['disabled'],
96 $form['third row'] = array(
97 '#prefix' => '<div class="' . $row_class . ' ctools-export-ui-row ctools-export-ui-third-row clearfix element-hidden">',
98 '#suffix' => '</div>',
99 'order' => $form['bottom row']['order'],
100 'sort' => $form['bottom row']['sort'],
102 unset($form['top row']);
103 unset($form['bottom row']);
105 // Modify the look and contents of existing form elements.
106 $form['second row']['storage']['#title'] = '';
107 $form['second row']['storage']['#options'] = array(
108 'all' => t('All storage'),
109 t('Normal') => t('In database'),
110 t('Default') => t('In code'),
111 t('Overridden') => t('Database overriding code'),
113 $form['second row']['disabled']['#title'] = '';
114 $form['second row']['disabled']['#options']['all'] = t('All status');
115 $form['third row']['sort']['#title'] = '';
117 // And finally, add our own.
118 $this->bases
= array();
119 foreach (views_fetch_base_tables() as $table => $info) {
120 $this->bases
[$table] = $info['title'];
123 $form['second row']['base'] = array(
125 '#options' => array_merge(array('all' => t('All types')), $this->bases
),
126 '#default_value' => 'all',
131 if (isset($form_state['object']->items
)) {
132 foreach ($form_state['object']->items
as $name => $view) {
133 if (!empty($view->tag
)) {
134 $view_tags = drupal_explode_tags($view->tag
);
135 foreach ($view_tags as $tag) {
143 $form['second row']['tag'] = array(
145 '#title' => t('Filter'),
146 '#options' => array_merge(array('all' => t('All tags')), array('none' => t('No tags')), $tags),
147 '#default_value' => 'all',
152 foreach (views_fetch_plugin_data('display') as $id => $info) {
153 if (!empty($info['admin'])) {
154 $displays[$id] = $info['admin'];
159 $form['second row']['display'] = array(
161 '#options' => array_merge(array('all' => t('All displays')), $displays),
162 '#default_value' => 'all',
167 function list_filter($form_state, $view) {
168 // Don't filter by tags if all is set up.
169 if ($form_state['values']['tag'] != 'all') {
170 // If none is selected check whether the view has a tag.
171 if ($form_state['values']['tag'] == 'none') {
172 return !empty($view->tag
);
175 // Check whether the tag can be found in the views tag.
176 return strpos($view->tag
, $form_state['values']['tag']) === FALSE;
179 if ($form_state['values']['base'] != 'all' && $form_state['values']['base'] != $view->base_table
) {
183 return parent
::list_filter($form_state, $view);
186 function list_sort_options() {
188 'disabled' => t('Enabled, name'),
192 'storage' => t('Storage'),
197 function list_build_row($view, &$form_state, $operations) {
198 if (!empty($view->human_name
)) {
199 $title = $view->human_name
;
202 $title = $view->get_title();
204 $title = $view->name
;
208 $paths = _views_ui_get_paths($view);
209 $paths = implode(", ", $paths);
211 $base = !empty($this->bases
[$view->base_table
]) ?
$this->bases
[$view->base_table
] : t('Broken');
213 $info = theme('views_ui_view_info', array('view' => $view, 'base' => $base));
215 // Reorder the operations so that enable is the default action for a templatic views
216 if (!empty($operations['enable'])) {
217 $operations = array('enable' => $operations['enable']) +
$operations;
221 switch ($form_state['values']['order']) {
223 $this->sorts
[$view->name
] = strtolower(empty($view->disabled
) . $title);
226 $this->sorts
[$view->name
] = strtolower($title);
229 $this->sorts
[$view->name
] = strtolower($paths);
232 $this->sorts
[$view->name
] = strtolower($view->tag
);
235 $this->sorts
[$view->name
] = strtolower($view->type
. $title);
239 $ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
241 $this->rows
[$view->name
] = array(
243 array('data' => $info, 'class' => array('views-ui-name')),
244 array('data' => check_plain($view->description
), 'class' => array('views-ui-description')),
245 array('data' => check_plain($view->tag
), 'class' => array('views-ui-tag')),
246 array('data' => $paths, 'class' => array('views-ui-path')),
247 array('data' => $ops, 'class' => array('views-ui-operations')),
249 'title' => t('Machine name: ') . check_plain($view->name
),
250 'class' => array(!empty($view->disabled
) ?
'ctools-export-ui-disabled' : 'ctools-export-ui-enabled'),
254 function list_render(&$form_state) {
255 views_include('admin');
256 views_ui_add_admin_css();
257 if (empty($_REQUEST['js'])) {
258 views_ui_check_advanced_help();
260 drupal_add_library('system', 'jquery.bbq');
261 views_add_js('views-list');
263 $this->active
= $form_state['values']['order'];
264 $this->order
= $form_state['values']['sort'];
266 $query = tablesort_get_query_parameters();
269 $this->tablesort_link(t('View name'), 'name', 'views-ui-name'),
270 array('data' => t('Description'), 'class' => array('views-ui-description')),
271 $this->tablesort_link(t('Tag'), 'tag', 'views-ui-tag'),
272 $this->tablesort_link(t('Path'), 'path', 'views-ui-path'),
273 array('data' => t('Operations'), 'class' => array('views-ui-operations')),
278 'rows' => $this->rows
,
279 'empty' => t('No views match the search criteria.'),
280 'attributes' => array('id' => 'ctools-export-ui-list-items'),
282 return theme('table', $table);
285 function tablesort_link($label, $field, $class) {
286 $title = t('sort by @s', array('@s' => $label));
289 if ($this->active
== $field) {
290 $initial = ($this->order
== 'asc') ?
'desc' : 'asc';
291 $label .= theme('tablesort_indicator', array('style' => $initial));
294 $query['order'] = $field;
295 $query['sort'] = $initial;
296 $link_options = array(
298 'attributes' => array('title' => $title),
301 $link = l($label, $_GET['q'], $link_options);
302 if ($this->active
== $field) {
306 return array('data' => $link, 'class' => $class);
309 function clone_page($js, $input, $item, $step = NULL) {
310 drupal_set_title($this->get_page_title('clone', $item));
312 $name = $item->{$this->plugin
['export']['key']};
315 'plugin' => $this->plugin
,
320 'form type' => 'clone',
321 'original name' => $name,
323 'no_redirect' => TRUE,
325 // Store these in case additional args are needed.
326 'function args' => func_get_args(),
329 $output = drupal_build_form('views_ui_clone_form', $form_state);
330 if (!empty($form_state['executed'])) {
331 $item->name
= $form_state['values']['name'];
332 $item->human_name
= $form_state['values']['human_name'];
334 views_ui_cache_set($item);
336 drupal_goto(ctools_export_ui_plugin_menu_path($this->plugin
, 'edit', $item->name
));
342 function add_template_page($js, $input, $name, $step = NULL) {
343 $templates = views_get_all_templates();
345 if (empty($templates[$name])) {
346 return MENU_NOT_FOUND
;
349 $template = $templates[$name];
351 // The template description probably describes the template, not the
352 // view that will be created from it, but users aren't that likely to
354 if (!empty($template->description
)) {
355 unset($template->description
);
358 $template->is_template
= TRUE;
359 $template->type
= t('Default');
361 $output = $this->clone_page($js, $input, $template, $step);
362 drupal_set_title(t('Create view from template @template', array('@template' => $template->get_human_name())));
366 function set_item_state($state, $js, $input, $item) {
367 ctools_export_set_object_status($item, $state);
371 drupal_goto(ctools_export_ui_plugin_base_path($this->plugin
));
374 return $this->list_page($js, $input);
378 function list_page($js, $input) {
379 // Remove filters values from session if filters are hidden.
380 if (!variable_get('views_ui_show_listing_filters', FALSE) && isset($_SESSION['ctools_export_ui'][$this->plugin
['name']])) {
381 unset($_SESSION['ctools_export_ui'][$this->plugin
['name']]);
384 // wrap output in a div for CSS
385 $output = parent
::list_page($js, $input);
386 if (is_string($output)) {
387 $output = '<div id="views-ui-list-page">' . $output . '</div>';
394 * Form callback to edit an exportable item using the wizard
396 * This simply loads the object defined in the plugin and hands it off.
398 function views_ui_clone_form($form, &$form_state) {
401 if (!isset($form_state['item'])) {
402 $view = views_get_view($form_state['original name']);
405 $view = $form_state['item'];
408 if (empty($form_state['item']->is_template
)) {
409 $name = format_plural($counter, 'Clone of', 'Clone @count of') . ' ' . $view->get_human_name();
412 $name = $view->get_human_name();
414 $name .= ' ' . $counter;
418 $machine_name = preg_replace('/[^a-z0-9_]+/', '_', drupal_strtolower($name));
419 } while (ctools_export_crud_load($form_state['plugin']['schema'], $machine_name));
421 $form['human_name'] = array(
422 '#type' => 'textfield',
423 '#title' => t('View name'),
424 '#default_value' => $name,
429 $form['name'] = array(
430 '#title' => t('View name'),
431 '#type' => 'machine_name',
435 '#machine_name' => array(
436 'exists' => 'ctools_export_ui_edit_name_exists',
437 'source' => array('human_name'),
441 $form['submit'] = array(
443 '#value' => t('Continue'),