/**
  * Page callback; Displays a listing of subqueues for a queue.
  */
 public function subqueues_page($js, $input, EntityQueue $queue)
 {
     $plugin = $this->plugin;
     drupal_set_title($this->get_page_title('subqueues', $queue));
     _entityqueue_set_breadcrumb();
     $header = array(array('data' => t('Id'), 'type' => 'property', 'specifier' => 'subqueue_id', 'class' => array('entityqueue-ui-subqueue-id')), array('data' => t('Subqueue'), 'type' => 'property', 'specifier' => 'label', 'class' => array('entityqueue-ui-subqueue-label')), array('data' => t('Operations'), 'class' => array('entityqueue-ui-subqueue-operations')));
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', $this->entityType);
     $query->entityCondition('bundle', $queue->name);
     $query->pager(50);
     $query->tableSort($header);
     $results = $query->execute();
     $ids = isset($results[$this->entityType]) ? array_keys($results[$this->entityType]) : array();
     $subqueues = $ids ? entity_load($this->entityType, $ids) : array();
     $rows = array();
     foreach ($subqueues as $subqueue) {
         $ops = array();
         if (entity_access('update', 'entityqueue_subqueue', $subqueue)) {
             $edit_op = str_replace('%entityqueue_subqueue', $subqueue->subqueue_id, ctools_export_ui_plugin_menu_path($plugin, 'edit subqueue', $queue->name));
             $ops[] = l(t('edit items'), $edit_op);
         }
         if (entity_access('delete', 'entityqueue_subqueue', $subqueue)) {
             $delete_op = str_replace('%entityqueue_subqueue', $subqueue->subqueue_id, ctools_export_ui_plugin_menu_path($plugin, 'delete subqueue', $queue->name));
             $ops[] = l(t('delete subqueue'), $delete_op);
         }
         $rows[] = array('data' => array(array('data' => $subqueue->subqueue_id, 'class' => array('entityqueue-ui-subqueue-id')), array('data' => filter_xss_admin($subqueue->label), 'class' => array('entityqueue-ui-subqueue-label')), array('data' => implode(' | ', $ops), 'class' => array('entityqueue-ui-subqueue-operations'))));
     }
     $render = array('table' => array('#theme' => 'table', '#header' => $header, '#rows' => $rows, '#empty' => t('There are no subqueues to display.')), 'pager' => array('#theme' => 'pager'));
     return $render;
 }
/**
 * Presets form.
 */
function spaces_preset_list($form, &$form_state, $export_ui)
{
    // Some setup for the spaces_preset_name_validation
    $form_state['plugin'] = $export_ui->plugin;
    $form_state['object'] =& $export_ui;
    $types = array();
    foreach (spaces_types(TRUE) as $type => $info) {
        $types[$type] = $info['title'];
    }
    $form['new'] = array('#tree' => FALSE, '#theme' => 'spaces_preset_list_new', 'space_type' => array('#title' => t('Type'), '#type' => 'select', '#options' => $types), 'name' => array('#type' => 'textfield', '#maxlength' => 64, '#size' => 32, '#title' => t('Machine ID'), '#element_validate' => array('spaces_preset_name_validate')), 'title' => array('#type' => 'textfield', '#maxlength' => 64, '#size' => 32, '#title' => t('Name')), 'submit' => array('#type' => 'submit', '#value' => t('Create new preset'), '#submit' => array('spaces_preset_list_new')));
    // Generate preset options.
    foreach ($types as $type => $title) {
        module_load_include('inc', 'spaces', 'spaces.admin');
        $presets = spaces_preset_load(NULL, $type, TRUE);
        ksort($presets);
        $form[$type] = spaces_preset_form($presets, $type, TRUE);
        $form[$type]['#title'] = t('@spacetype presets', array('@spacetype' => $title));
        $form[$type]['#description'] = t('Select a default preset for each new @spacetype.', array('@spacetype' => $title));
        $plugin = $export_ui->plugin;
        foreach ($presets as $name => $item) {
            // Note: Creating this list seems a little clumsy, but can't think of
            // better ways to do this.
            $allowed_operations = drupal_map_assoc(array_keys($plugin['allowed operations']));
            $not_allowed_operations = array('import');
            if ($item->type == t('Normal')) {
                $not_allowed_operations[] = 'revert';
            } elseif ($item->type == t('Overridden')) {
                $not_allowed_operations[] = 'delete';
            } else {
                $not_allowed_operations[] = 'revert';
                $not_allowed_operations[] = 'delete';
            }
            $not_allowed_operations[] = empty($item->disabled) ? 'enable' : 'disable';
            foreach ($not_allowed_operations as $op) {
                // Remove the operations that are not allowed for the specific exportable.
                unset($allowed_operations[$op]);
            }
            $operations = array();
            foreach ($allowed_operations as $op) {
                $operations[$op] = array('title' => $plugin['allowed operations'][$op]['title'], 'href' => ctools_export_ui_plugin_menu_path($plugin, $op, $name));
                if (!empty($plugin['allowed operations'][$op]['token'])) {
                    $operations[$op]['query'] = array('token' => drupal_get_token($op));
                }
            }
            $form[$type]['storage'][$item->name] = array('#type' => 'markup', '#markup' => isset($item->disabled) && $item->disabled ? t('Disabled') : check_plain($item->type));
            $form[$type]['actions'][$item->name] = array('#type' => 'markup', '#markup' => theme('links', array('links' => $operations)));
            $form[$type]["spaces_preset_{$type}"][$name] = array();
        }
    }
    $form = system_settings_form($form);
    return $form;
}
 /**
  * Get the form info for the wizard.
  *
  * This gets the form info out of the plugin, then adds defaults based on
  * how we want edit forms to work.
  *
  * Overriding this can allow child UIs to tweak this info for specialized
  * wizards.
  *
  * @param array $form_state
  *   The already created form state.
  */
 function get_wizard_info(&$form_state)
 {
     if (!isset($form_state['step'])) {
         $form_state['step'] = NULL;
     }
     $export_key = $this->plugin['export']['key'];
     // When cloning, the name of the item being cloned is referenced in the
     // path, not the name of this item.
     if ($form_state['form type'] == 'clone') {
         $name = $form_state['original name'];
     } else {
         $name = $form_state['item']->{$export_key};
     }
     $form_info = !empty($this->plugin['form info']) ? $this->plugin['form info'] : array();
     $form_info += array('id' => 'ctools_export_ui_edit', 'path' => ctools_export_ui_plugin_menu_path($this->plugin, $form_state['form type'], $name) . '/%step', 'show trail' => TRUE, 'free trail' => TRUE, 'show back' => $form_state['form type'] == 'add', 'show return' => FALSE, 'show cancel' => TRUE, 'finish callback' => 'ctools_export_ui_wizard_finish', 'next callback' => 'ctools_export_ui_wizard_next', 'back callback' => 'ctools_export_ui_wizard_back', 'cancel callback' => 'ctools_export_ui_wizard_cancel', 'order' => array(), 'import order' => array('import' => t('Import code'), 'settings' => t('Settings')));
     // Set the order of forms based on the op if we have a specific one.
     if (isset($form_info[$form_state['form type'] . ' order'])) {
         $form_info['order'] = $form_info[$form_state['form type'] . ' order'];
     }
     // We have generic fallback forms we can use if they are not specified,
     // and they automatically delegate back to the UI object. Use these if
     // not specified.
     foreach ($form_info['order'] as $key => $title) {
         if (empty($form_info['forms'][$key])) {
             $form_info['forms'][$key] = array('form id' => 'ctools_export_ui_edit_item_wizard_form');
         }
     }
     // 'free trail' means the wizard can freely go back and form from item
     // via the trail and not with next/back buttons.
     if ($form_state['form type'] == 'add' || $form_state['form type'] == 'import' && empty($form_state['item']->{$export_key})) {
         $form_info['free trail'] = FALSE;
     }
     return $form_info;
 }
Ejemplo n.º 4
0
 function clone_page($js, $input, $item, $step = NULL)
 {
     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, 'function args' => func_get_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;
 }
 /**
  * Page callback to import information for an exportable item.
  */
 function import_page($js, $input, $step = NULL)
 {
     drupal_set_title($this->get_page_title('import'));
     // Import is basically a multi step wizard form, so let's go ahead and
     // use CTools' wizard.inc for it.
     // If a step not set, they are trying to create a new item. If a step
     // is set, they're in the process of creating an item.
     if (!empty($step)) {
         $item = $this->edit_cache_get(NULL, 'import');
     }
     if (empty($item)) {
         $item = ctools_export_crud_new($this->plugin['schema']);
     }
     $form_state = array('plugin' => $this->plugin, 'object' => &$this, 'ajax' => $js, 'item' => $item, 'op' => 'add', 'form type' => 'import', 'rerender' => TRUE, 'no_redirect' => TRUE, 'step' => $step, 'function args' => func_get_args());
     // import always uses the wizard.
     $output = $this->edit_execute_form_wizard($form_state);
     if (!empty($form_state['executed'])) {
         $export_key = $this->plugin['export']['key'];
         drupal_goto(str_replace('%ctools_export_ui', $form_state['item']->{$export_key}, $this->plugin['redirect']['add']));
     }
     return $output;
     return;
     $form_info = array('id' => 'ctools_export_ui_import', 'path' => ctools_export_ui_plugin_menu_path($this->plugin, 'import') . '/%step', 'return path' => $this->plugin['redirect']['import'], 'show trail' => TRUE, 'show back' => TRUE, 'show return' => FALSE, 'show cancel' => TRUE, 'finish callback' => 'ctools_export_ui_import_finish', 'cancel callback' => 'ctools_export_ui_import_cancel', 'order' => array('code' => t('Import code'), 'edit' => t('Edit')), 'forms' => array('code' => array('form id' => 'ctools_export_ui_import_code'), 'edit' => array('form id' => 'ctools_export_ui_import_edit')));
     $form_state = array('plugin' => $this->plugin, 'input' => $input, 'rerender' => TRUE, 'no_redirect' => TRUE, 'object' => &$this, 'export' => '', 'overwrite' => FALSE, 'function args' => func_get_args());
     if ($step == 'code') {
         // This is only used if the BACK button was hit.
         if (!empty($_SESSION['ctools_export_ui_import'][$this->plugin['name']])) {
             $form_state['item'] = $_SESSION['ctools_export_ui_import'][$this->plugin['name']];
             $form_state['export'] = $form_state['item']->export_ui_code;
             $form_state['overwrite'] = $form_state['item']->export_ui_allow_overwrite;
         }
     } else {
         if ($step == 'begin') {
             $step = 'code';
             if (!empty($_SESSION['ctools_export_ui_import'][$this->plugin['name']])) {
                 unset($_SESSION['ctools_export_ui_import'][$this->plugin['name']]);
             }
         } else {
             if ($step != 'code') {
                 $form_state['item'] = $_SESSION['ctools_export_ui_import'][$this->plugin['name']];
                 $form_state['op'] = 'add';
                 if (!empty($form_state['item']->export_ui_allow_overwrite)) {
                     // if allow overwrite was enabled, set this to 'edit' only if the key already existed.
                     $export_key = $this->plugin['export']['key'];
                     if (ctools_export_crud_load($this->plugin['schema'], $form_state['item']->{$export_key})) {
                         $form_state['op'] = 'edit';
                     }
                 }
             }
         }
     }
     ctools_include('wizard');
     return ctools_wizard_multistep_form($form_info, $step, $form_state);
 }
 /**
  * Submit the filter/sort form.
  *
  * This submit handler is actually responsible for building up all of the
  * rows that will later be rendered, since it is doing the filtering and
  * sorting.
  *
  * For the most part, you should not need to override this method, as the
  * fiddly bits call through to other functions.
  */
 function list_form_submit(&$form, &$form_state)
 {
     // Filter and re-sort the pages.
     $plugin = $this->plugin;
     $schema = ctools_export_get_schema($this->plugin['schema']);
     $prefix = ctools_export_ui_plugin_base_path($plugin);
     foreach ($this->items as $name => $item) {
         // Call through to the filter and see if we're going to render this
         // row. If it returns TRUE, then this row is filtered out.
         if ($this->list_filter($form_state, $item)) {
             continue;
         }
         // Note: Creating this list seems a little clumsy, but can't think of
         // better ways to do this.
         $allowed_operations = drupal_map_assoc(array_keys($plugin['allowed operations']));
         //Cannot find the code that returns the list of possible operations, so I'm going to add extras here, which is not neat.
         //$allowed_operations['edit terms'] = 'edit terms';
         $not_allowed_operations = array('import');
         if ($item->{$schema['export']['export type string']} == t('Normal')) {
             $not_allowed_operations[] = 'revert';
         } elseif ($item->{$schema['export']['export type string']} == t('Overridden')) {
             $not_allowed_operations[] = 'delete';
         } else {
             $not_allowed_operations[] = 'revert';
             $not_allowed_operations[] = 'delete';
         }
         //$not_allowed_operations[] = empty($item->disabled) ? 'enable' : 'disable';
         //Forcing 'disable' and 'enable' to be disabled always. This should be done in the install schema with 'can disable' => FALSE, but that would
         //mean reinstalling the module and I don't think it works properly.
         $not_allowed_operations[] = 'disable';
         $not_allowed_operations[] = 'enable';
         foreach ($not_allowed_operations as $op) {
             // Remove the operations that are not allowed for the specific
             // exportable.
             unset($allowed_operations[$op]);
         }
         $operations = array();
         foreach ($allowed_operations as $op) {
             $operations[$op] = array('title' => $plugin['allowed operations'][$op]['title'], 'href' => ctools_export_ui_plugin_menu_path($plugin, $op, $name));
             if (!empty($plugin['allowed operations'][$op]['ajax'])) {
                 $operations[$op]['attributes'] = array('class' => array('use-ajax'));
             }
             if (!empty($plugin['allowed operations'][$op]['token'])) {
                 $operations[$op]['query'] = array('token' => drupal_get_token($op));
             }
         }
         $this->list_build_row($item, $form_state, $operations);
     }
     // Now actually sort
     if ($form_state['values']['sort'] == 'desc') {
         arsort($this->sorts);
     } else {
         asort($this->sorts);
     }
     // Nuke the original.
     $rows = $this->rows;
     $this->rows = array();
     // And restore.
     foreach ($this->sorts as $name => $title) {
         $this->rows[$name] = $rows[$name];
     }
 }