You are here

class mlpanels_panels_renderer_editor in Multilingual Panels 7

Editor panel class replacement.

Hierarchy

Expanded class hierarchy of mlpanels_panels_renderer_editor

See also

panels_renderer_editor()

1 string reference to 'mlpanels_panels_renderer_editor'
mlpanels.module in ./mlpanels.module
Multilingual panels.

File

./mlpanels_panels_renderer_editor.class.php, line 12
Class file to control the main Panels editor.

View source
class mlpanels_panels_renderer_editor extends panels_renderer_editor {
  var $commands = array();
  var $admin = TRUE;
  var $no_edit_links = FALSE;

  /**
   * Receive and store the display object to be rendered.
   *
   * This is a psuedo-constructor that should typically be called immediately
   * after object construction.
   */
  function init($plugin, &$display) {
    drupal_add_css(drupal_get_path('module', 'mlpanels') . '/' . MLPANELS_RENDERER_EDITOR_CLASS . '.css');
    drupal_add_js(drupal_get_path('module', 'mlpanels') . '/' . MLPANELS_RENDERER_EDITOR_CLASS . '.js');

    // Pass settings.
    drupal_add_js(array(
      'mlpanels' => _mlpanels_settings(),
    ), 'setting');
    return parent::init($plugin, $display);
  }

  /**
   * AJAX entry point to add a new pane.
   */
  function ajax_add_pane($region = NULL, $type_name = NULL, $subtype_name = NULL, $step = NULL) {

    // Check if we should skip pane translation.
    if (_mlpanels_pane_skip($type_name, $subtype_name)) {

      // Pass to default renderer.
      return parent::ajax_add_pane($region, $type_name, $subtype_name, $step);
    }

    // Show messages.
    $settings = _mlpanels_settings();
    if ($settings['show_messages'] && empty($step)) {
      drupal_set_message(t('Please fill default pane settings,
      you can translate them later if you want by editing pane settings.'));
    }

    // Return default method.
    return parent::ajax_add_pane($region, $type_name, $subtype_name, $step);
  }

  /**
   * AJAX entry point to edit a pane.
   */
  function ajax_edit_pane($pid = NULL, $step = NULL) {
    if (empty($this->cache->display->content[$pid])) {
      ctools_modal_render(t('Error'), t('Invalid pane id.'));
    }
    $pane =& $this->cache->display->content[$pid];

    // Check if we should skip pane translation.
    if (_mlpanels_pane_skip($pane->type, $pane->subtype)) {

      // Pass to default renderer.
      return parent::ajax_edit_pane($pid, $step);
    }
    $content_type = ctools_get_content_type($pane->type);
    $subtype = ctools_content_get_subtype($content_type, $pane->subtype);
    $settings = _mlpanels_settings();
    if (empty($step)) {
      $messages[] = t('You can translate settings for different languages,
      but you must set %renderer as display renderer in order to see result.', array(
        '%renderer' => t('Multilingual Standard'),
      ));
    }
    if ($settings['show_types']) {
      $messages[] = t('Pane type to disable %type', array(
        '%type' => $pane->type . '::' . $pane->subtype,
      ));
    }

    // Get language.
    $path = explode('/', $_GET['q']);
    $tmp = explode('_', end($path));
    if ($tmp[0] == 'mlpanels') {
      $conf_lng = $tmp[1];
    }
    if (empty($conf_lng)) {
      $conf_lng = LANGUAGE_NONE;
    }

    // Prepare language dependent config.
    if (!empty($pane->configuration['mlpanels'])) {
      $ml_config = $pane->configuration['mlpanels'];
      $ml_config[LANGUAGE_NONE] = $pane->configuration;
      unset($ml_config[LANGUAGE_NONE]['mlpanels']);
    }
    else {
      $ml_config[LANGUAGE_NONE] = $pane->configuration;
    }
    if (!empty($ml_config[$conf_lng])) {
      $configuration = $ml_config[$conf_lng];
    }
    else {
      $messages[] = t('No configuration exists for this language yet, using default.');
      $configuration = $ml_config[LANGUAGE_NONE];
    }

    // Safety check.
    if (isset($configuration['mlpanels'])) {
      unset($configuration['mlpanels']);
    }

    // Change finish button text.
    $finish_text = t('Finish');
    if ($conf_lng != LANGUAGE_NONE) {
      if (_mlpanels_settings('keep_window')) {
        $finish_text = t('Save Translation and Continue');
      }
      else {
        $finish_text = t('Save Translation and Finish');
      }
    }
    $form_state = array(
      'display' => &$this->cache->display,
      'contexts' => $this->cache->display->context,
      'pane' => &$pane,
      'display cache' => &$this->cache,
      'ajax' => TRUE,
      'modal' => TRUE,
      'modal return' => TRUE,
      'commands' => array(),
    );
    $form_info = array(
      'path' => $this
        ->get_url('edit-pane', $pid, '%step', 'mlpanels_' . $conf_lng),
      'show cancel' => TRUE,
      'finish text' => $finish_text,
      'next callback' => 'panels_ajax_edit_pane_next',
      'finish callback' => 'panels_ajax_edit_pane_finish',
      'cancel callback' => 'panels_ajax_edit_pane_cancel',
    );

    // This is used to get our form in form alter.
    if ($conf_lng != LANGUAGE_NONE) {
      $form_info['untranslate text'] = t('Remove Translation');
      $form_info['untranslate hidden'] = empty($ml_config[$conf_lng]);
    }

    // Building form.
    $output = ctools_content_form('edit', $form_info, $form_state, $content_type, $pane->subtype, $subtype, $configuration, $step);

    // Add language links to the form.
    $languages = array(
      LANGUAGE_NONE => (object) array(
        'name' => t('Default'),
        'language' => LANGUAGE_NONE,
      ),
    ) + language_list();
    foreach ($languages as $lng) {
      $class = array(
        'ctools-use-modal',
      );
      $class[] = $lng->language;
      if (empty($ml_config[$lng->language])) {
        $class[] = 'empty';
      }
      if ($conf_lng == $lng->language) {
        $class[] = 'current';
      }
      $links[] = l($lng->name, $this
        ->get_url('edit-pane', $pid, $form_state['step'], 'mlpanels_' . $lng->language), array(
        'attributes' => array(
          'class' => $class,
        ),
        'html' => TRUE,
      ));
    }
    $output['mlpanels'] = array(
      '#markup' => theme('item_list', array(
        'items' => $links,
        'attributes' => array(
          'class' => array(
            'mlpanels_lnd_list',
          ),
        ),
      )),
    );
    $output['mlpanels_messages'] = array(
      '#markup' => '<div class="message-target"></div>',
    );

    // If $rc is FALSE, there was no actual form.
    if ($output === FALSE || !empty($form_state['cancel'])) {

      // Dismiss the modal.
      $this->commands[] = ctools_modal_command_dismiss();
    }
    elseif (!empty($form_state['clicked_button']) && $form_state['clicked_button']['#wizard type'] == 'untranslate') {

      // Unset surrent translation.
      unset($ml_config[$conf_lng]);

      // Update pane configuration.
      $form_state['pane']->configuration = array(
        'mlpanels' => $ml_config,
      ) + $ml_config[LANGUAGE_NONE];

      // References get blown away with AJAX caching. This will fix that.
      $this->cache->display->content[$pid] = $form_state['pane'];
      panels_edit_cache_set($this->cache);
      $this
        ->command_update_pane($pid);
      if (_mlpanels_settings('keep_window') && $conf_lng != LANGUAGE_NONE) {
        drupal_set_message(t('Translation removed.'));
        $this->commands[] = ajax_command_remove('#modal-content .messages');
        $this->commands[] = ajax_command_html('#modal-content .message-target', theme('status_messages'));
        $this->commands[] = ajax_command_invoke('#modal-content input.pane-untranslate', 'hide');
        $this->commands[] = ajax_command_invoke('.mlpanels_lnd_list a.' . $conf_lng, 'addClass', array(
          'empty',
        ));
      }
      else {
        $this->commands[] = ctools_modal_command_dismiss();
      }
    }
    elseif (!empty($form_state['complete'])) {

      // Save our settings for selected language.
      $ml_config[$conf_lng] = $configuration;

      // Update pane configuration.
      $form_state['pane']->configuration = array(
        'mlpanels' => $ml_config,
      ) + $ml_config[LANGUAGE_NONE];

      // References get blown away with AJAX caching. This will fix that.
      $this->cache->display->content[$pid] = $form_state['pane'];
      panels_edit_cache_set($this->cache);
      $this
        ->command_update_pane($pid);
      if (_mlpanels_settings('keep_window') && $conf_lng != LANGUAGE_NONE) {
        drupal_set_message(t('Translation updated.'));
        $this->commands[] = ajax_command_remove('#modal-content .messages');
        $this->commands[] = ajax_command_html('#modal-content .message-target', theme('status_messages'));
        $this->commands[] = ajax_command_invoke('#modal-content input.pane-untranslate', 'show');
        $this->commands[] = ajax_command_invoke('.mlpanels_lnd_list a.' . $conf_lng, 'removeClass', array(
          'empty',
        ));
      }
      else {
        $this->commands[] = ctools_modal_command_dismiss();
      }
    }
    else {

      // Show messages.
      if ($settings['show_messages']) {
        if (isset($messages)) {
          foreach ($messages as $msg) {
            drupal_set_message($msg);
          }
        }
      }

      // This overwrites any previous commands.
      $this->commands = ctools_modal_form_render($form_state, $output);
      array_unshift($this->commands, array(
        'command' => 'mlpanels_ckefix',
      ));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
mlpanels_panels_renderer_editor::$admin property TRUE if this renderer is rendering in administrative mode which will allow layouts to have extra functionality. Overrides panels_renderer_editor::$admin
mlpanels_panels_renderer_editor::$commands property An array of AJAX commands to return. If populated it will automatically be used by the AJAX router. Overrides panels_renderer_editor::$commands
mlpanels_panels_renderer_editor::$no_edit_links property Set to true if edit links (for panes and regions) should not be displayed. This can be used for special edit modes such as layout change and layout builder that do not actually have real content. Overrides panels_renderer_editor::$no_edit_links
mlpanels_panels_renderer_editor::ajax_add_pane function AJAX entry point to add a new pane. Overrides panels_renderer_editor::ajax_add_pane
mlpanels_panels_renderer_editor::ajax_edit_pane function AJAX entry point to edit a pane. Overrides panels_renderer_editor::ajax_edit_pane
mlpanels_panels_renderer_editor::init function Receive and store the display object to be rendered. Overrides panels_renderer_standard::init
panels_renderer_editor::add_meta function Attach out-of-band page metadata (e.g., CSS and JS). Overrides panels_renderer_standard::add_meta 1
panels_renderer_editor::ajax_access_add_test function AJAX entry point for to add a visibility rule.
panels_renderer_editor::ajax_access_configure_test function AJAX entry point for to configure vsibility rule.
panels_renderer_editor::ajax_access_settings function AJAX entry point to configure access settings for a pane.
panels_renderer_editor::ajax_cache_method function AJAX entry point to configure the cache method for a pane or the display.
panels_renderer_editor::ajax_cache_settings function AJAX entry point to configure the cache settings for a pane or the display.
panels_renderer_editor::ajax_hide function AJAX command to show a pane.
panels_renderer_editor::ajax_layout function AJAX Router function for layout owned AJAX calls.
panels_renderer_editor::ajax_lock function AJAX entry point to configure CSS for a pane.
panels_renderer_editor::ajax_panel_title function AJAX entry point to select which pane is currently the title.
panels_renderer_editor::ajax_pane_css function AJAX entry point to configure CSS for a pane.
panels_renderer_editor::ajax_select_content function AJAX command to present a dialog with a list of available content.
panels_renderer_editor::ajax_show function AJAX command to show a pane.
panels_renderer_editor::ajax_style function AJAX Router function for style owned AJAX calls.
panels_renderer_editor::ajax_style_settings function AJAX entry point to configure the style for a display, region or pane.
panels_renderer_editor::ajax_style_type function AJAX entry point to select the style for a display, region or pane.
panels_renderer_editor::command_add_pane function Create a command array to add a new pane. 1
panels_renderer_editor::command_update_display_links function Create a command to update the links on a display after a change was made.
panels_renderer_editor::command_update_pane function Create a command array to redraw a pane. 1
panels_renderer_editor::command_update_region_links function Create a command to update the links on a region after a change was made.
panels_renderer_editor::edit function Display edit rendering.
panels_renderer_editor::get_categories function Create a list of categories from all of the content type.
panels_renderer_editor::get_category function Return the category name and the category key of a given content type.
panels_renderer_editor::get_display_links function Get the links for a panel display.
panels_renderer_editor::get_panels_storage_op_for_ajax function Get the Panels storage oparation for a given renderer AJAX method. Overrides panels_renderer_standard::get_panels_storage_op_for_ajax 1
panels_renderer_editor::get_pane_links function Render the links to display when editing a pane.
panels_renderer_editor::get_region_links function Render the links to display when editing a region.
panels_renderer_editor::get_style function Get the appropriate style from the panel in the cache.
panels_renderer_editor::get_style_links function Get the style links.
panels_renderer_editor::get_url function Generate a URL path for the AJAX editor.
panels_renderer_editor::render function Build inner content, then hand off to layout-specified theme function for final render step. Overrides panels_renderer_standard::render 1
panels_renderer_editor::render_pane function Render a pane using its designated style. Overrides panels_renderer_standard::render_pane 1
panels_renderer_editor::render_region function Render a single panel region. Overrides panels_renderer_standard::render_region 1
panels_renderer_standard::$display property The fully-loaded Panels display object that is to be rendered. "Fully loaded" is defined as: 1. Having been produced by panels_load_displays(), whether or this page request or at some time in the past and the object was exported. 2. Having…
panels_renderer_standard::$meta_location property Where to add standard meta information. There are three possibilities:
panels_renderer_standard::$plugin property The plugin that defines this handler.
panels_renderer_standard::$plugins property An associative array of loaded plugins. Used primarily as a central location for storing plugins that require additional loading beyond reading the plugin definition, which is already statically cached by ctools_get_plugins(). An example is layout…
panels_renderer_standard::$prefix property Include rendered HTML prior to the layout.
panels_renderer_standard::$prepared property A multilevel array of data prepared for rendering. The first level of the array indicates the type of prepared data. The standard renderer populates and uses two top-level keys, 'panes' and 'regions':
panels_renderer_standard::$prep_run property Boolean state variable, indicating whether or not the prepare() method has been run.
panels_renderer_standard::$rendered property A multilevel array of rendered data. The first level of the array indicates the type of rendered data, typically with up to three keys: 'layout', 'regions', and 'panes'. The relevant rendered data is stored as the value…
panels_renderer_standard::$show_empty_layout property Boolean flag indicating whether to render the layout even if all rendered regions are blank. If FALSE, the layout renders as an empty string (without prefix or suffix) if not in administrative mode.
panels_renderer_standard::$suffix property Include rendered HTML after the layout.
panels_renderer_standard::add_css function Add CSS information to the renderer.
panels_renderer_standard::prepare function Prepare the attached display for rendering. 1
panels_renderer_standard::prepare_panes function Prepare the list of panes to be rendered, accounting for visibility/access settings and rendering order. 1
panels_renderer_standard::prepare_regions function Prepare the list of regions to be rendered.
panels_renderer_standard::render_layout function Perform display/layout-level render operations.
panels_renderer_standard::render_panes function Render all prepared panes, first by dispatching to their plugin's render callback, then handing that output off to the pane's style plugin. 1
panels_renderer_standard::render_pane_content function Render the interior contents of a single pane. 1
panels_renderer_standard::render_regions function Render all prepared regions, placing already-rendered panes into their appropriate positions therein. 1