class views_ui

CTools Export UI class handler for Views UI.

Hierarchy

Expanded class hierarchy of views_ui

16 string references to 'views_ui'
ViewsArgumentDefaultTest::testArgumentDefaultNoOptions in tests/views_argument_default.test
Tests the use of a default argument plugin that provides no options.
ViewsSqlTest::enableViewsUi in tests/views_query.test
This function allows to enable views ui from a higher class which can't change the setup function anymore.
ViewsSqlTest::setUp in tests/views_query.test
Sets up a Drupal site for running functional and integration tests.
ViewsUiGroupbyTestCase::setUp in tests/views_groupby.test
Sets up a Drupal site for running functional and integration tests.
ViewsUIWizardHelper::setUp in tests/views_ui.test
Sets up a Drupal site for running functional and integration tests.

... See full list

File

plugins/export_ui/views_ui.class.php, line 13

View source
class views_ui extends ctools_export_ui {
    
    /**
     *
     */
    public function init($plugin) {
        // We modify the plugin info here so that we take the defaults and twiddle,
        // rather than completely override them.
        // Reset the edit path to match what we're really using.
        $plugin['menu']['items']['edit']['path'] = 'view/%ctools_export_ui/edit';
        $plugin['menu']['items']['clone']['path'] = 'view/%ctools_export_ui/clone';
        $plugin['menu']['items']['clone']['type'] = MENU_VISIBLE_IN_BREADCRUMB;
        $plugin['menu']['items']['export']['path'] = 'view/%ctools_export_ui/export';
        $plugin['menu']['items']['export']['type'] = MENU_VISIBLE_IN_BREADCRUMB;
        $plugin['menu']['items']['enable']['path'] = 'view/%ctools_export_ui/enable';
        $plugin['menu']['items']['disable']['path'] = 'view/%ctools_export_ui/disable';
        $plugin['menu']['items']['delete']['path'] = 'view/%ctools_export_ui/delete';
        $plugin['menu']['items']['delete']['type'] = MENU_VISIBLE_IN_BREADCRUMB;
        $plugin['menu']['items']['revert']['path'] = 'view/%ctools_export_ui/revert';
        $plugin['menu']['items']['revert']['type'] = MENU_VISIBLE_IN_BREADCRUMB;
        $prefix_count = count(explode('/', $plugin['menu']['menu prefix']));
        $plugin['menu']['items']['add-template'] = array(
            'path' => 'template/%/add',
            'title' => 'Add from template',
            'page callback' => 'ctools_export_ui_switcher_page',
            'page arguments' => array(
                $plugin['name'],
                'add_template',
                $prefix_count + 2,
            ),
            'load arguments' => array(
                $plugin['name'],
            ),
            'access callback' => 'ctools_export_ui_task_access',
            'access arguments' => array(
                $plugin['name'],
                'add_template',
                $prefix_count + 2,
            ),
            'type' => MENU_CALLBACK,
        );
        return parent::init($plugin);
    }
    
    /**
     *
     */
    public function hook_menu(&$items) {
        // We are using our own 'edit' still, rather than having edit on this
        // object (maybe in the future) so unset the edit callbacks. Store this so
        // we can put them back as sometimes they're needed again laster.
        $stored_items = $this->plugin['menu']['items'];
        // We leave these to make sure the operations still exist in the plugin so
        // that the path finder.
        unset($this->plugin['menu']['items']['edit']);
        unset($this->plugin['menu']['items']['add']);
        unset($this->plugin['menu']['items']['import']);
        unset($this->plugin['menu']['items']['edit callback']);
        parent::hook_menu($items);
        $this->plugin['menu']['items'] = $stored_items;
    }
    
    /**
     *
     */
    public function load_item($item_name) {
        return views_ui_cache_load($item_name);
    }
    
    /**
     *
     */
    public function list_form(&$form, &$form_state) {
        $row_class = 'container-inline';
        if (!variable_get('views_ui_show_listing_filters', FALSE)) {
            $row_class .= " element-invisible";
        }
        views_include('admin');
        parent::list_form($form, $form_state);
        // CTools only has two rows. We want four. That's why we create our own
        // structure.
        $form['bottom row']['submit']['#attributes']['class'][] = 'js-hide';
        $form['first row'] = array(
            '#prefix' => '<div class="' . $row_class . ' ctools-export-ui-row ctools-export-ui-first-row clearfix">',
            '#suffix' => '</div>',
            'search' => $form['top row']['search'],
            'submit' => $form['bottom row']['submit'],
            'reset' => $form['bottom row']['reset'],
        );
        $form['second row'] = array(
            '#prefix' => '<div class="' . $row_class . ' ctools-export-ui-row ctools-export-ui-second-row clearfix">',
            '#suffix' => '</div>',
            'storage' => $form['top row']['storage'],
            'disabled' => $form['top row']['disabled'],
        );
        $form['third row'] = array(
            '#prefix' => '<div class="' . $row_class . ' ctools-export-ui-row ctools-export-ui-third-row clearfix element-hidden">',
            '#suffix' => '</div>',
            'order' => $form['bottom row']['order'],
            'sort' => $form['bottom row']['sort'],
        );
        unset($form['top row']);
        unset($form['bottom row']);
        // Modify the look and contents of existing form elements.
        $form['second row']['storage']['#title'] = '';
        $form['second row']['storage']['#options'] = array(
            'all' => t('All storage'),
            t('Normal') => t('In database'),
            t('Default') => t('In code'),
            t('Overridden') => t('Database overriding code'),
        );
        $form['second row']['disabled']['#title'] = '';
        $form['second row']['disabled']['#options']['all'] = t('All status');
        $form['third row']['sort']['#title'] = '';
        // And finally, add our own.
        $this->bases = array();
        foreach (views_fetch_base_tables() as $table => $info) {
            $this->bases[$table] = $info['title'];
        }
        $form['second row']['base'] = array(
            '#type' => 'select',
            '#options' => array_merge(array(
                'all' => t('All types'),
            ), $this->bases),
            '#default_value' => 'all',
            '#weight' => -1,
        );
        $tags = array();
        if (isset($form_state['object']->items)) {
            foreach ($form_state['object']->items as $view) {
                if (!empty($view->tag)) {
                    $view_tags = drupal_explode_tags($view->tag);
                    foreach ($view_tags as $tag) {
                        $tags[$tag] = $tag;
                    }
                }
            }
        }
        asort($tags);
        $form['second row']['tag'] = array(
            '#type' => 'select',
            '#title' => t('Filter'),
            '#options' => array_merge(array(
                'all' => t('All tags'),
            ), array(
                'none' => t('No tags'),
            ), $tags),
            '#default_value' => 'all',
            '#weight' => -9,
        );
        $displays = array();
        foreach (views_fetch_plugin_data('display') as $id => $info) {
            if (!empty($info['admin'])) {
                $displays[$id] = $info['admin'];
            }
        }
        asort($displays);
        $form['second row']['display'] = array(
            '#type' => 'select',
            '#options' => array_merge(array(
                'all' => t('All displays'),
            ), $displays),
            '#default_value' => 'all',
            '#weight' => -1,
        );
    }
    
    /**
     *
     */
    public function list_filter($form_state, $view) {
        // Don't filter by tags if all is set up.
        if ($form_state['values']['tag'] != 'all') {
            // If none is selected check whether the view has a tag.
            if ($form_state['values']['tag'] == 'none') {
                return !empty($view->tag);
            }
            else {
                // Check whether the tag can be found in the views tag.
                $tag = '';
                if (isset($view->tag)) {
                    $tag = $view->tag;
                }
                $form_state_tag = '';
                if (isset($form_state['values']['tag'])) {
                    $form_state_tag = $form_state['values']['tag'];
                }
                return strpos($tag, $form_state_tag) === FALSE;
            }
        }
        if ($form_state['values']['base'] != 'all' && $form_state['values']['base'] != $view->base_table) {
            return TRUE;
        }
        return parent::list_filter($form_state, $view);
    }
    
    /**
     *
     */
    public function list_sort_options() {
        return array(
            'disabled' => t('Enabled, name'),
            'name' => t('Name'),
            'path' => t('Path'),
            'tag' => t('Tag'),
            'storage' => t('Storage'),
        );
    }
    
    /**
     *
     */
    public function list_build_row($view, &$form_state, $operations) {
        if (!empty($view->human_name)) {
            $title = $view->human_name;
        }
        else {
            $title = $view->get_title();
            if (empty($title)) {
                $title = $view->name;
            }
        }
        $paths = _views_ui_get_paths($view);
        $paths = implode(", ", $paths);
        $base = !empty($this->bases[$view->base_table]) ? $this->bases[$view->base_table] : t('Broken');
        $info = theme('views_ui_view_info', array(
            'view' => $view,
            'base' => $base,
        ));
        // Reorder the operations so that enable is the default action for a
        // templatic views.
        if (!empty($operations['enable'])) {
            $operations = array(
                'enable' => $operations['enable'],
            ) + $operations;
        }
        // Set up sorting.
        switch ($form_state['values']['order']) {
            case 'disabled':
                $this->sorts[$view->name] = strtolower(empty($view->disabled) . $title);
                break;
            case 'name':
                $this->sorts[$view->name] = strtolower($title);
                break;
            case 'path':
                $this->sorts[$view->name] = strtolower($paths);
                break;
            case 'tag':
                $this->sorts[$view->name] = strtolower($view->tag);
                break;
            case 'storage':
                $this->sorts[$view->name] = strtolower($view->type . $title);
                break;
        }
        $theme_args = array(
            'links' => $operations,
            'attributes' => array(
                'class' => array(
                    'links',
                    'inline',
                ),
            ),
        );
        $ops = theme('links__ctools_dropbutton', $theme_args);
        $this->rows[$view->name] = array(
            'data' => array(
                array(
                    'data' => $info,
                    'class' => array(
                        'views-ui-name',
                    ),
                ),
                array(
                    'data' => check_plain($view->description),
                    'class' => array(
                        'views-ui-description',
                    ),
                ),
                array(
                    'data' => check_plain($view->tag),
                    'class' => array(
                        'views-ui-tag',
                    ),
                ),
                array(
                    'data' => $paths,
                    'class' => array(
                        'views-ui-path',
                    ),
                ),
                array(
                    'data' => $ops,
                    'class' => array(
                        'views-ui-operations',
                    ),
                ),
            ),
            'title' => t('Machine name: ') . check_plain($view->name),
            'class' => array(
                !empty($view->disabled) ? 'ctools-export-ui-disabled' : 'ctools-export-ui-enabled',
            ),
        );
    }
    
    /**
     *
     */
    public function list_render(&$form_state) {
        views_include('admin');
        views_ui_add_admin_css();
        if (empty($_REQUEST['js'])) {
            views_ui_check_advanced_help();
        }
        drupal_add_library('system', 'jquery.bbq');
        views_add_js('views-list');
        $this->active = $form_state['values']['order'];
        $this->order = $form_state['values']['sort'];
        $header = array(
            $this->tablesort_link(t('View name'), 'name', 'views-ui-name'),
            array(
                'data' => t('Description'),
                'class' => array(
                    'views-ui-description',
                ),
            ),
            $this->tablesort_link(t('Tag'), 'tag', 'views-ui-tag'),
            $this->tablesort_link(t('Path'), 'path', 'views-ui-path'),
            array(
                'data' => t('Operations'),
                'class' => array(
                    'views-ui-operations',
                ),
            ),
        );
        $table = array(
            'header' => $header,
            'rows' => $this->rows,
            'empty' => t('No views match the search criteria.'),
            'attributes' => array(
                'id' => 'ctools-export-ui-list-items',
            ),
        );
        return theme('table', $table);
    }
    
    /**
     *
     */
    public function tablesort_link($label, $field, $class) {
        $title = t('sort by @s', array(
            '@s' => $label,
        ));
        $initial = 'asc';
        if ($this->active == $field) {
            $initial = $this->order == 'asc' ? 'desc' : 'asc';
            $label .= theme('tablesort_indicator', array(
                'style' => $initial,
            ));
        }
        $query['order'] = $field;
        $query['sort'] = $initial;
        $link_options = array(
            'html' => TRUE,
            'attributes' => array(
                'title' => $title,
            ),
            'query' => $query,
        );
        $link = l($label, $_GET['q'], $link_options);
        if ($this->active == $field) {
            $class .= ' active';
        }
        return array(
            'data' => $link,
            'class' => $class,
        );
    }
    
    /**
     *
     */
    public function clone_page($js, $input, $item, $step = NULL) {
        $args = func_get_args();
        drupal_set_title($this->get_page_title('clone', $item));
        $name = $item->{$this->plugin['export']['key']};
        $form_state = array(
            'plugin' => $this->plugin,
            'object' => &$this,
            'ajax' => $js,
            'item' => $item,
            'op' => 'add',
            'form type' => 'clone',
            'original name' => $name,
            'rerender' => TRUE,
            'no_redirect' => TRUE,
            'step' => $step,
            // Store these in case additional args are needed.
'function args' => $args,
        );
        $output = drupal_build_form('views_ui_clone_form', $form_state);
        if (!empty($form_state['executed'])) {
            $item->name = $form_state['values']['name'];
            $item->human_name = $form_state['values']['human_name'];
            $item->vid = NULL;
            views_ui_cache_set($item);
            drupal_goto(ctools_export_ui_plugin_menu_path($this->plugin, 'edit', $item->name));
        }
        return $output;
    }
    
    /**
     *
     */
    public function add_template_page($js, $input, $name, $step = NULL) {
        $templates = views_get_all_templates();
        if (empty($templates[$name])) {
            return MENU_NOT_FOUND;
        }
        $template = $templates[$name];
        // The template description probably describes the template, not the view
        // that will be created from it, but users aren't that likely to touch it.
        if (!empty($template->description)) {
            unset($template->description);
        }
        $template->is_template = TRUE;
        $template->type = t('Default');
        $output = $this->clone_page($js, $input, $template, $step);
        drupal_set_title(t('Create view from template @template', array(
            '@template' => $template->get_human_name(),
        )));
        return $output;
    }
    
    /**
     *
     */
    public function set_item_state($state, $js, $input, $item) {
        ctools_export_set_object_status($item, $state);
        menu_rebuild();
        if (!$js) {
            drupal_goto(ctools_export_ui_plugin_base_path($this->plugin));
        }
        else {
            return $this->list_page($js, $input);
        }
    }
    
    /**
     *
     */
    public function list_page($js, $input) {
        // Remove filters values from session if filters are hidden.
        if (!variable_get('views_ui_show_listing_filters', FALSE) && isset($_SESSION['ctools_export_ui'][$this->plugin['name']])) {
            unset($_SESSION['ctools_export_ui'][$this->plugin['name']]);
        }
        // Wrap output in a div for CSS.
        $output = parent::list_page($js, $input);
        if (is_string($output)) {
            $output = '<div id="views-ui-list-page">' . $output . '</div>';
        }
        return $output;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
ctools_export_ui::$name property
ctools_export_ui::$options property
ctools_export_ui::$plugin property
ctools_export_ui::access public function Menu callback to determine if an operation is accessible. 1
ctools_export_ui::add_page public function
ctools_export_ui::build_operations public function Builds the operation links for a specific exportable item.
ctools_export_ui::delete_form_submit public function Deletes exportable items from the database.
ctools_export_ui::delete_page public function Page callback to delete an exportable item.
ctools_export_ui::disable_page public function Callback to disable a page.
ctools_export_ui::edit_cache_clear public function Clear the object cache for the currently edited item.
ctools_export_ui::edit_cache_get public function Retrieve the item currently being edited from the object cache.
ctools_export_ui::edit_cache_get_key public function Figure out what the cache key is for this object.
ctools_export_ui::edit_cache_set public function Cache the item currently currently being edited.
ctools_export_ui::edit_cache_set_key public function
ctools_export_ui::edit_execute_form public function Execute the form.
ctools_export_ui::edit_execute_form_standard public function Execute the standard form for editing.
ctools_export_ui::edit_execute_form_wizard public function Execute the wizard for editing.
ctools_export_ui::edit_finish_validate public function Perform a final validation check before allowing the form to be
finished.
ctools_export_ui::edit_form public function Provide the actual editing form. 1
ctools_export_ui::edit_form_import public function Import form. Provides simple helptext instructions and textarea for
pasting a export definition.
ctools_export_ui::edit_form_import_submit public function Submit callback for import form.
ctools_export_ui::edit_form_import_validate public function Import form validate handler.
ctools_export_ui::edit_form_submit public function Handle the submission of the edit form. 2
ctools_export_ui::edit_form_validate public function Validate callback for the edit form.
ctools_export_ui::edit_page public function Main entry point to edit an item.
ctools_export_ui::edit_save_form public function Called to save the final product from the edit form.
ctools_export_ui::edit_wizard_back public function Wizard &#039;back&#039; callback when using a wizard to edit an item.
ctools_export_ui::edit_wizard_cancel public function Wizard &#039;cancel&#039; callback when using a wizard to edit an item.
ctools_export_ui::edit_wizard_finish public function Wizard &#039;cancel&#039; callback when using a wizard to edit an item. 1
ctools_export_ui::edit_wizard_next public function Wizard &#039;next&#039; callback when using a wizard to edit an item. 1
ctools_export_ui::enable_page public function Callback to enable a page.
ctools_export_ui::export_page public function Page callback to display export information for an exportable item.
ctools_export_ui::get_page_title public function Get a page title for the current page from our plugin strings.
ctools_export_ui::get_wizard_info public function Get the form info for the wizard. 1
ctools_export_ui::import_page public function Page callback to import information for an exportable item.
ctools_export_ui::list_css public function Add listing CSS to the page.
ctools_export_ui::list_footer public function Render a footer to go after thie list.
ctools_export_ui::list_form_submit public function Submit the filter/sort form.
ctools_export_ui::list_form_validate public function Validate the filter/sort form.
ctools_export_ui::list_header public function Render a header to go before the list.
ctools_export_ui::list_search_fields public function Provide a list of fields to test against for the default &quot;search&quot; widget. 1
ctools_export_ui::list_table_header public function Provide the table header. 2
ctools_export_ui::redirect public function Perform a drupal_goto() to the location provided by the plugin for the
operation.
views_ui::add_template_page public function
views_ui::clone_page public function Main entry point to clone an item. Overrides ctools_export_ui::clone_page
views_ui::hook_menu public function hook_menu() entry point. Overrides ctools_export_ui::hook_menu
views_ui::init public function Fake constructor -- this is easier to deal with than the real
constructor because we are retaining PHP4 compatibility, which
would require all child classes to implement their own constructor.
Overrides ctools_export_ui::init
views_ui::list_build_row public function Build a row based on the item. Overrides ctools_export_ui::list_build_row
views_ui::list_filter public function Determine if a row should be filtered out. Overrides ctools_export_ui::list_filter
views_ui::list_form public function Create the filter/sort form at the top of a list of exports. Overrides ctools_export_ui::list_form
views_ui::list_page public function Master entry point for handling a list. Overrides ctools_export_ui::list_page
views_ui::list_render public function Render all of the rows together. Overrides ctools_export_ui::list_render
views_ui::list_sort_options public function Provide a list of sort options. Overrides ctools_export_ui::list_sort_options
views_ui::load_item public function Called by ctools_export_ui_load to load the item. Overrides ctools_export_ui::load_item
views_ui::set_item_state public function Set an item&#039;s state to enabled or disabled and output to user. Overrides ctools_export_ui::set_item_state
views_ui::tablesort_link public function