You are here

class panelizer_defaults_ui in Panelizer 7.3

Same name and namespace in other branches
  1. 7.2 plugins/export_ui/panelizer_defaults_ui.class.php \panelizer_defaults_ui

@file Contains the administrative UI for selectable panelizer defaults.

Hierarchy

Expanded class hierarchy of panelizer_defaults_ui

1 string reference to 'panelizer_defaults_ui'
panelizer_defaults.inc in plugins/export_ui/panelizer_defaults.inc

File

plugins/export_ui/panelizer_defaults_ui.class.php, line 7
Contains the administrative UI for selectable panelizer defaults.

View source
class panelizer_defaults_ui extends ctools_export_ui {
  function init($plugin) {
    ctools_include('export');
    $this->plugin = $plugin;

    // Get rid of the list parent.
    unset($this->plugin['menu']['items']['list callback']);
  }
  function hook_menu(&$items) {

    // Change the item to a tab.
    $this->plugin['menu']['items']['list']['type'] = MENU_LOCAL_TASK;
    $this->plugin['menu']['items']['list']['weight'] = -6;
    $this->plugin['menu']['items']['list']['title'] = 'List defaults';

    // menu local actions are weird.
    $this->plugin['menu']['items']['add']['path'] = 'list/add';
    $this->plugin['menu']['items']['import']['path'] = 'list/import';

    // Edit is being handled elsewhere.
    unset($this->plugin['menu']['items']['edit callback']);
    unset($this->plugin['menu']['items']['access']);
    foreach (panelizer_operations() as $path => $operation) {
      $location = isset($operation['ui path']) ? $operation['ui path'] : $path;
      if (isset($this->plugin['menu']['items'][$location])) {
        unset($this->plugin['menu']['items'][$location]);
      }
    }

    // Change the callbacks for everything.
    foreach ($this->plugin['menu']['items'] as $key => $item) {

      // The item has already been set; continue to next item to avoid shifting
      // items onto the page arguments array more than once.
      if ($this->plugin['menu']['items'][$key]['access callback'] == 'panelizer_has_choice_callback') {
        continue;
      }
      $this->plugin['menu']['items'][$key]['access callback'] = 'panelizer_has_choice_callback';
      $this->plugin['menu']['items'][$key]['access arguments'] = array(
        3,
        4,
        '',
      );
      $this->plugin['menu']['items'][$key]['page callback'] = 'panelizer_export_ui_switcher_page';
      array_unshift($this->plugin['menu']['items'][$key]['page arguments'], 4);
      array_unshift($this->plugin['menu']['items'][$key]['page arguments'], 3);
    }
    parent::hook_menu($items);
  }
  function list_page($js, $input) {
    if ($substitute = $this->entity_handler
      ->get_substitute($this->entity_view_mode, $this->entity_bundle)) {
      $url = $this->plugin['menu']['menu prefix'] . '/' . $substitute;
      drupal_set_message(t('This display is managed by the !view_mode display.', array(
        '!view_mode' => l($substitute, $url),
      )), 'status', FALSE);
      return '';
    }
    drupal_set_title($this->entity_handler
      ->get_bundle_title($this->entity_bundle));
    return parent::list_page($js, $input);
  }
  function list_filter($form_state, $item) {

    // Reminder: This returns TRUE to exclude the item.
    if ($this->entity_handler->entity_type != $item->panelizer_type) {
      return TRUE;
    }
    if ($this->entity_bundle != $item->panelizer_key) {
      return TRUE;
    }
    if ($this->entity_view_mode != $item->view_mode) {
      return TRUE;
    }
    if (!$this->entity_handler
      ->access_default_panelizer_object($item)) {
      return TRUE;
    }
    if (empty($item->title) && $item->name == implode(':', array(
      $this->entity_handler->entity_type,
      $this->entity_bundle,
      'default',
    ))) {
      $item->title = t('Default');
    }
    return parent::list_filter($form_state, $item);
  }

  /**
   * Extends ctools_export_ui::edit_form().
   *
   * Change the 'exists' callback so that we can build the actual export object
   * name before checking if it exists.
   */
  function edit_form(&$form, &$form_state) {
    parent::edit_form($form, $form_state);
    foreach ($form['info'] as $export_key => $settings) {
      if (!empty($form['info'][$export_key]['#machine_name']['exists'])) {
        $form['info'][$export_key]['#machine_name']['exists'] = 'panelizer_defaults_ui_edit_name_exists';
      }
    }
  }
  function edit_execute_form_standard(&$form_state) {
    if ($form_state['form type'] == 'clone') {
      $form_state['item']->title = t('Clone of') . ' ' . $form_state['item']->title;
      $form_state['item']->name = '';
    }
    else {
      if ($form_state['op'] == 'add') {
        $form_state['item']->panelizer_type = $this->entity_handler->entity_type;
        $form_state['item']->panelizer_key = $this->entity_bundle;
        $form_state['item']->view_mode = $this->entity_view_mode;
        $form_state['item']->display = $this->entity_handler
          ->get_default_display($this->entity_bundle, $this->entity_view_mode);
      }
    }
    return parent::edit_execute_form_standard($form_state);
  }
  function edit_form_validate(&$form, &$form_state) {

    // Build the actual name of the object for ctools
    $export_key = $this->plugin['export']['key'];
    $name = panelizer_defaults_ui_build_export_name($form_state['values'][$export_key], $this);
    form_set_value($form['info'][$export_key], $name, $form_state);
  }

  // Simplest way to override the drupal_goto from parent.
  // Why isn't delete using the redirect system everything else is?
  function delete_page($js, $input, $item) {
    $clone = clone $item;

    // Change the name into the title so the form shows the right value.
    // @todo file a bug against CTools to use admin title if available.
    $clone->name = $clone->title;
    $form_state = array(
      'plugin' => $this->plugin,
      'object' => &$this,
      'ajax' => $js,
      'item' => $clone,
      'op' => $item->export_type & EXPORT_IN_CODE ? 'revert' : 'delete',
      'rerender' => TRUE,
      'no_redirect' => TRUE,
    );
    $output = drupal_build_form('ctools_export_ui_delete_confirm_form', $form_state);
    if (!empty($form_state['executed'])) {
      ctools_export_crud_delete($this->plugin['schema'], $item);
      $export_key = $this->plugin['export']['key'];
      drupal_set_message(t($this->plugin['strings']['confirmation'][$form_state['op']]['success'], array(
        '%title' => $item->title,
      )));
      drupal_goto(ctools_export_ui_plugin_base_path($this->plugin));
    }
    return $output;
  }

}

Members

Namesort descending Modifiers Type Description 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::clone_page public function Main entry point to clone an item.
ctools_export_ui::delete_form_submit public function Deletes exportable items from the database.
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_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_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_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 'back' callback when using a wizard to edit an item.
ctools_export_ui::edit_wizard_cancel public function Wizard 'cancel' callback when using a wizard to edit an item.
ctools_export_ui::edit_wizard_finish public function Wizard 'cancel' callback when using a wizard to edit an item. 1
ctools_export_ui::edit_wizard_next public function Wizard 'next' 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_build_row public function Build a row based on the item. 2
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 public function Create the filter/sort form at the top of a list of exports. 2
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_render public function Render all of the rows together.
ctools_export_ui::list_search_fields public function Provide a list of fields to test against for the default "search" widget. 1
ctools_export_ui::list_sort_options public function Provide a list of sort options. 2
ctools_export_ui::list_table_header public function Provide the table header. 2
ctools_export_ui::load_item public function Called by ctools_export_ui_load to load the item.
ctools_export_ui::redirect public function Perform a drupal_goto() to the location provided by the plugin for the operation.
ctools_export_ui::set_item_state public function Set an item's state to enabled or disabled and output to user.
panelizer_defaults_ui::delete_page function Page callback to delete an exportable item. Overrides ctools_export_ui::delete_page
panelizer_defaults_ui::edit_execute_form_standard function Execute the standard form for editing. Overrides ctools_export_ui::edit_execute_form_standard
panelizer_defaults_ui::edit_form function Extends ctools_export_ui::edit_form(). Overrides ctools_export_ui::edit_form
panelizer_defaults_ui::edit_form_validate function Validate callback for the edit form. Overrides ctools_export_ui::edit_form_validate
panelizer_defaults_ui::hook_menu function hook_menu() entry point. Overrides ctools_export_ui::hook_menu
panelizer_defaults_ui::init 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
panelizer_defaults_ui::list_filter function Determine if a row should be filtered out. Overrides ctools_export_ui::list_filter
panelizer_defaults_ui::list_page function Master entry point for handling a list. Overrides ctools_export_ui::list_page