【问题标题】:drupal panels ipe toolbardrupal 面板 ipe 工具栏
【发布时间】:2016-06-09 22:25:49
【问题描述】:

我向面板 ipe 工具栏添加了自定义按钮。工具栏仅在您具有正确权限且页面为面板化页面时显示。我还想为其他页面显示 ipe 工具栏,其中包含该页面的选项卡(查看/编辑/开发/翻译)。有可能吗?

【问题讨论】:

    标签: php drupal toolbar panels


    【解决方案1】:

    是的,这是可能的。我的一个项目也有类似的需求。我在自定义模块中所做的是:

    1. 当按钮不存在时使用 hook_page_alter 添加 ipe 工具栏(Panels IPE 在它们存在时添加它们)
    2. 使用 hook_theme_registry_alter 来使用我自己的模板函数,而不是 Panels IPE 提供的模板函数。
    3. 创建一个自定义主题函数来添加我的自定义按钮

    在代码中是这样的:

    /**
     * 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多