简体   繁体   中英

drupal panels ipe toolbar

I added custom buttons to the panels ipe toolbar. The toolbar only shows when you have the right permissions, and when the page is a panelized page. I want to display the ipe toolbar also for other pages, containing that page his tabs (view/edit/devel/translate). Is it possible?

yes, this is possible. I had a similar need in one of my projects. What I did in a custom module was:

  1. Use hook_page_alter to add the ipe toolbar when buttons DON'T exist (Panels IPE adds them when they do exist)
  2. Use hook_theme_registry_alter to use my own template function instead of the one provided by Panels IPE.
  3. Create a custom theme function that adds my custom buttons

In code it is something like this:

/**
 * Implements of hook_page_alter()
 */
function MYMODULE_page_alter(&$page) {
  // Check if Panels IPE is turned on.
  if (!module_exists('panels_ipe'))
    return;

  // Let Panels IPE add the buttons if they exist > If there are no buttons
  // then we'll still add the toolbar anyway.
  $buttons = &drupal_static('panels_ipe_toolbar_buttons', array());
  if (!empty($buttons)) {
    return;
  }

  $output = theme('panels_ipe_toolbar', array('buttons' => $buttons));

  $page['page_bottom']['panels_ipe'] = array(
    '#markup' => $output,
  );
}

/**
 * Implements hook_theme_registry_alter().
 */
function MYMODULE_theme_registry_alter(&$theme_registry) {
  // Check if Panels IPE is turned on.
  if (!module_exists('panels_ipe'))
    return;
  // Inject our own theme function instead of the one from Panels IPE
  $theme_registry['panels_ipe_toolbar']['function'] = 'theme_MYMODULE_panels_ipe_toolbar';
}

// This function is to be adjusted to add buttons and things.
function theme_MYMODULE_panels_ipe_toolbar($vars) {
  $buttons = $vars['buttons'];

  $output = "<div id='panels-ipe-control-container' class='clearfix'>";
  foreach ($buttons as $key => $ipe_buttons) {
    $output .= "<div id='panels-ipe-control-$key' class='panels-ipe-control'>";

    // Controls in this container will appear when the IPE is not on.
    $output .= '<div class="panels-ipe-button-container clearfix">';
    foreach ($ipe_buttons as $button) {
      $output .= is_string($button) ? $button : drupal_render($button);
    }
    $output .= '</div>';

    // Controls in this container will appear when the IPE is on. It is usually
    // filled via AJAX.
    $output .= '<div class="panels-ipe-form-container clearfix"></div>';
    $output .= '</div>';
  }

  $output .= "</div>";

  return $output;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM